function LinkWidget::validateTitleElement
Same name and namespace in other branches
- 11.x core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php \Drupal\link\Plugin\Field\FieldWidget\LinkWidget::validateTitleElement()
- 10 core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php \Drupal\link\Plugin\Field\FieldWidget\LinkWidget::validateTitleElement()
- 9 core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php \Drupal\link\Plugin\Field\FieldWidget\LinkWidget::validateTitleElement()
- 8.9.x core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php \Drupal\link\Plugin\Field\FieldWidget\LinkWidget::validateTitleElement()
Form element validation handler for the 'title' element.
Conditionally requires the link title if a URL value was filled in.
Deprecated
in drupal:11.4.0 and is removed from drupal:12.0.0. Instead, validation is performed by the LinkTitleRequiredConstraint on the LinkItem field type.
See also
https://www.drupal.org/node/3554139
File
-
core/
modules/ link/ src/ Plugin/ Field/ FieldWidget/ LinkWidget.php, line 182
Class
- LinkWidget
- Plugin implementation of the 'link' widget.
Namespace
Drupal\link\Plugin\Field\FieldWidgetCode
public static function validateTitleElement(&$element, FormStateInterface $form_state, $form) {
@trigger_error(__METHOD__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:12.0.0. Instead, validation is performed by the LinkTitleRequiredConstraint on the LinkItem field type. See https://www.drupal.org/node/3554139', E_USER_DEPRECATED);
if ($element['uri']['#value'] !== '' && $element['title']['#value'] === '') {
// We expect the field name placeholder value to be wrapped in $this->t()
// here, so it won't be escaped again as it's already marked safe.
$form_state->setError($element['title'], new TranslatableMarkup('@title field is required if there is @uri input.', [
'@title' => $element['title']['#title'],
'@uri' => $element['uri']['#title'],
]));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.