You are here

public static function LinkWidget::validateTitleNoLink in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php \Drupal\link\Plugin\Field\FieldWidget\LinkWidget::validateTitleNoLink()

Form element validation handler for the 'title' element.

Requires the URL value if a link title was filled in.

File

core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php, line 173

Class

LinkWidget
Plugin implementation of the 'link' widget.

Namespace

Drupal\link\Plugin\Field\FieldWidget

Code

public static function validateTitleNoLink(&$element, FormStateInterface $form_state, $form) {
  if ($element['uri']['#value'] === '' && $element['title']['#value'] !== '') {
    $form_state
      ->setError($element['uri'], t('The @uri field is required when the @title field is specified.', [
      '@title' => $element['title']['#title'],
      '@uri' => $element['uri']['#title'],
    ]));
  }
}