You are here

public function TreeWidget::validate in Field Menu 8

Validate the Menu item Key field.

File

src/Plugin/Field/FieldWidget/TreeWidget.php, line 162

Class

TreeWidget
Plugin implementation of the 'field_menu_tree_widget' widget.

Namespace

Drupal\field_menu\Plugin\Field\FieldWidget

Code

public function validate($element, FormStateInterface $form_state) {
  $menu_item_key = isset($element['menu_item_key']['#value']) ? $element['menu_item_key']['#value'] : '';
  if (strlen($menu_item_key) == 0) {
    $form_state
      ->setValueForElement($element['menu_item_key'], '');
    if ($element['menu_title']['#value']) {
      $form_state
        ->setError($element['menu_item_key'], $this
        ->t("You must select a menu item if you have set a title"));
    }
  }
}