You are here

public static function LinkIconItem::elementValidateLinkIcon in Link Icon 8

Validates predefined link title.

Since Link title is not required, we make sure that it is not empty if the URL field is not. And vice versa.

File

src/LinkIconItem.php, line 56

Class

LinkIconItem
Modify plugin implementation of the 'link' field settings form.

Namespace

Drupal\linkicon

Code

public static function elementValidateLinkIcon(&$element, FormStateInterface $form_state, $context) {
  if ($element['uri']['#value'] !== '' && $element['title']['#value'] === '') {
    $element['title']['#required'] = TRUE;
    $form_state
      ->setError($element['title'], t('@name field is required. Title must be entered if URL is provided.', [
      '@name' => $element['title']['#title'],
    ]));
  }
  if ($element['uri']['#value'] === '' && $element['title']['#value'] !== '') {
    $element['uri']['#required'] = TRUE;
    $form_state
      ->setError($element['uri'], t('@name field is required. URL must be entered if title is provided.', [
      '@name' => $element['uri']['#title'],
    ]));
  }
}