You are here

function cami_form_menu_link_content_menu_link_content_form_alter in Custom Active Menu Item 8

Implements hook_form_FORM_ID_alter() for menu_link_edit().

File

./cami.module, line 8

Code

function cami_form_menu_link_content_menu_link_content_form_alter(&$form, FormStateInterface $form_state) {
  $menu_link = $form_state
    ->getFormObject()
    ->getEntity();
  $menu_link_options = $menu_link->link
    ->first()->options ?: [];
  $defaults = isset($menu_link_options['cami']) ? $menu_link_options['cami'] : [];
  $form['options']['cami'] = array(
    '#type' => 'details',
    '#open' => FALSE,
    '#title' => t('Custom Active Menu Item'),
    '#weight' => 1,
    '#tree' => TRUE,
  );
  $form['options']['cami']['pages'] = array(
    '#type' => 'textarea',
    '#title' => t('Pages'),
    '#description' => t("Pages where the menu item will be active, Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are blog for the blog page and blog/* for every personal blog."),
    '#default_value' => isset($defaults['pages']) ? $defaults['pages'] : '',
  );
  $form['actions']['submit']['#submit'][] = 'cami_menu_link_content_form_submit';
}