You are here

public static function MenuLinkWidget::preRenderMenuDetails in Menu Link (Field) 8

Pre-render callback: Builds a renderable array for the menu link widget.

Parameters

array $element: A renderable array.

Return value

array A renderable array.

File

src/Plugin/Field/FieldWidget/MenuLinkWidget.php, line 170

Class

MenuLinkWidget
Provides a widget for the menu_link field type.

Namespace

Drupal\menu_link\Plugin\Field\FieldWidget

Code

public static function preRenderMenuDetails($element) : array {
  $element['menu']['enabled'] = $element['enabled'];
  $element['menu']['title'] = $element['title'];
  $element['menu']['description'] = $element['description'];
  $element['menu']['menu_parent'] = $element['menu_parent'];
  $element['menu']['weight'] = $element['weight'];

  // Hide the elements when enabled is disabled.
  foreach ([
    'title',
    'description',
    'menu_parent',
    'weight',
  ] as $form_element) {
    $element['menu'][$form_element]['#states'] = [
      'invisible' => [
        'input[name="' . $element['menu']['enabled']['#name'] . '"]' => [
          'checked' => FALSE,
        ],
      ],
    ];
  }
  unset($element['enabled'], $element['title'], $element['description'], $element['menu_parent'], $element['weight']);
  return $element;
}