You are here

public function MenuEditForm::form in UIkit Components 8.2

Same name and namespace in other branches
  1. 8.3 src/Form/MenuEditForm.php \Drupal\uikit_components\Form\MenuEditForm::form()

Gets the actual form array to be built.

Overrides MenuForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Form/MenuEditForm.php, line 17

Class

MenuEditForm
Base form for menu edit forms.

Namespace

Drupal\uikit_components\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $t_args = [
    ':list' => UIkitComponents::getComponentURL('list'),
    ':nav' => UIkitComponents::getComponentURL('nav'),
    ':subnav' => UIkitComponents::getComponentURL('subnav'),
    ':grid' => UIkitComponents::getComponentURL('grid'),
  ];
  $description_links = [
    $this
      ->t('<a href=":list" target="_blank">List</a>', $t_args),
    $this
      ->t('<a href=":nav" target="_blank">Nav</a>', $t_args),
    $this
      ->t('<a href=":subnav" target="_blank">Subnav</a>', $t_args),
  ];
  $links = [
    '#markup' => implode(', ', $description_links),
  ];
  $width_classes = UIkitComponents::getNavWidthClasses($this->entity
    ->id()) ? UIkitComponents::getNavWidthClasses($this->entity
    ->id()) : '';
  $form['label']['#weight'] = -10;
  $form['id']['#weight'] = -9;
  $form['description']['#weight'] = -8;
  $form['menu_style'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('UIkit menu style'),
    '#description' => $this
      ->t('<p>Select the UIkit component to set a default style for the menu. Some options will provide additional settings. Examples: @examples</p>', [
      '@examples' => render($links),
    ]),
    '#options' => [
      $this
        ->t('List')
        ->render() => [
        'uk-list' => $this
          ->t('Default list'),
        'uk-list-line' => $this
          ->t('Line list'),
        'uk-list-space' => $this
          ->t('Spaced list'),
        'uk-list-striped' => $this
          ->t('Striped list'),
      ],
      'uk-nav' => $this
        ->t('Nav'),
      $this
        ->t('Subnav')
        ->render() => [
        'uk-subnav' => $this
          ->t('Default subnav'),
        'uk-subnav-line' => $this
          ->t('Subnav line'),
        'uk-subnav-pill' => $this
          ->t('Subnav pill'),
      ],
    ],
    '#empty_value' => '',
    '#default_value' => UIkitComponents::getMenuStyle($this->entity
      ->id()),
    '#weight' => -7,
  ];
  $form['menu_style_wrapper_widths'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Menu wrapper width classes'),
    '#description' => $this
      ->t('Enter the <a href=":grid" target="_blank">width classes</a>, separated with a space, to wrap the menu in.', $t_args),
    '#default_value' => $width_classes,
    '#weight' => -2,
  ];
  return $form;
}