function FormHooks::formMenuLinkContentFormAlter

Same name and namespace in other branches
  1. 11.x core/themes/admin/src/Hook/FormHooks.php \Drupal\admin\Hook\FormHooks::formMenuLinkContentFormAlter()

Implements hook_form_BASE_FORM_ID_alter() for MenuLinkContentForm.

Alters the menu_link_content_form by organizing form elements into different 'details' sections.

Attributes

#[Hook('form_menu_link_content_form_alter')]

File

core/themes/admin/src/Hook/FormHooks.php, line 252

Class

FormHooks
Provides form related hook implementations.

Namespace

Drupal\admin\Hook

Code

public function formMenuLinkContentFormAlter(array &$form) : void {
  $form['#theme'] = [
    'menu_link_form',
  ];
  $form['#attached']['library'][] = 'admin/form-two-columns';
  $form['advanced'] = [
    '#type' => 'container',
    '#weight' => 10,
    '#accordion' => TRUE,
  ];
  $form['menu_parent']['#wrapper_attributes'] = [
    'class' => [
      'accordion__item',
      'entity-meta__header',
    ],
  ];
  $form['menu_parent']['#prefix'] = '<div class="accordion">';
  $form['menu_parent']['#suffix'] = '</div>';
  $form['menu_parent']['#group'] = 'advanced';
  $form['menu_link_display_settings'] = [
    '#type' => 'details',
    '#group' => 'advanced',
    '#title' => $this->t('Display settings'),
    '#attributes' => [
      'class' => [
        'entity-meta__options',
      ],
    ],
    '#tree' => FALSE,
    '#accordion' => TRUE,
  ];
  if (!empty($form['weight'])) {
    $form['menu_link_display_settings']['weight'] = $form['weight'];
    unset($form['weight'], $form['menu_link_display_settings']['weight']['#weight']);
  }
  if (!empty($form['expanded'])) {
    $form['menu_link_display_settings']['expanded'] = $form['expanded'];
    unset($form['expanded']);
  }
  if (isset($form['description'])) {
    $form['menu_link_description'] = [
      '#type' => 'details',
      '#group' => 'advanced',
      '#title' => $this->t('Description'),
      '#attributes' => [
        'class' => [
          'entity-meta__description',
        ],
      ],
      '#tree' => FALSE,
      '#accordion' => TRUE,
      'description' => $form['description'],
    ];
    unset($form['description']);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.