You are here

function uikit_components_form_menu_link_content_form_alter in UIkit Components 8

Same name and namespace in other branches
  1. 8.3 includes/alter.inc \uikit_components_form_menu_link_content_form_alter()
  2. 8.2 includes/alter.inc \uikit_components_form_menu_link_content_form_alter()

Implements hook_form_BASE_FORM_ID_alter().

File

./uikit_components.module, line 45
UIkit Components.

Code

function uikit_components_form_menu_link_content_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $menu_link = $form_state
    ->getFormObject()
    ->getEntity();
  $menu_link_options = $menu_link->link
    ->first()->options ?: [];

  // Translatable string arguments.
  $t_args = [
    ':navbar' => Url::fromUri('https://getuikit.com/v2/docs/navbar.html')
      ->toString(),
  ];

  // UIkit navbar component options.
  $form['menu_item_type'] = [
    '#type' => 'select',
    '#title' => t('Menu item type'),
    '#default_value' => !empty($menu_link_options['menu_item_type']) ? $menu_link_options['menu_item_type'] : 0,
    '#options' => [
      0 => t('Normal menu item'),
      'nav_header' => t('Navigation header'),
      'nav_divider' => t('Navigation divider'),
    ],
    '#description' => t('Select the type of menu item this is. <em class="placeholder">Navigation header</em> and <em class="placeholder">Navigation divider</em> are special menu items from the <a href=":navbar" target="_blank">UIkit navbar component</a>.', $t_args),
  ];
  $form['actions']['submit']['#submit'][] = 'uikit_components_menu_link_content_form_submit';
}