You are here

public static function MiconMenuWidget::validateIconElement in Micon 2.x

Same name and namespace in other branches
  1. 8 micon_menu/src/Plugin/Field/FieldWidget/MiconMenuWidget.php \Drupal\micon_menu\Plugin\Field\FieldWidget\MiconMenuWidget::validateIconElement()

Recursively clean up options array if no data-icon is set.

File

micon_menu/src/Plugin/Field/FieldWidget/MiconMenuWidget.php, line 44

Class

MiconMenuWidget
Plugin implementation of the 'link' widget.

Namespace

Drupal\micon_menu\Plugin\Field\FieldWidget

Code

public static function validateIconElement($element, FormStateInterface $form_state, $form) {
  parent::validateIconElement($element, $form_state, $form);
  if ($values = $form_state
    ->getValue('link')) {
    foreach ($values as $value) {

      // Support menu_link_attributes module.
      if ($attributes = $form_state
        ->getValue('attributes')) {
        if (!empty($value['options']['attributes'])) {
          $attributes += $value['options']['attributes'];
          $form_state
            ->setValue('attributes', $attributes);
        }
      }
    }
  }
}