public function MenuEditForm::form in UIkit Components 8.3
Same name and namespace in other branches
- 8.2 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
- Extends the MenuForm form builder for the menu edit forms.
Namespace
Drupal\uikit_components\FormCode
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'),
':width' => UIkitComponents::getComponentURL('width'),
];
$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-bullet' => $this
->t('Bullet list'),
'uk-list-divider' => $this
->t('Divided 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-divider' => $this
->t('Divided subnav'),
'uk-subnav-pill' => $this
->t('Pill subnav'),
],
],
'#empty_value' => '',
'#default_value' => UIkitComponents::getMenuStyle($this->entity
->id()),
'#weight' => -7,
];
$form['menu_style_list_large'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Large modifier'),
'#description' => $this
->t('Check to increase the spacing between list items.'),
'#default_value' => UIkitComponents::getLargeList($this->entity
->id()),
'#weight' => -6,
'#states' => [
'visible' => [
[
':input[name="menu_style"]' => [
'value' => 'uk-list',
],
],
'or',
[
':input[name="menu_style"]' => [
'value' => 'uk-list-bullet',
],
],
'or',
[
':input[name="menu_style"]' => [
'value' => 'uk-list-divider',
],
],
'or',
[
':input[name="menu_style"]' => [
'value' => 'uk-list-striped',
],
],
],
],
];
$form['menu_style_nav_style_modifiers'] = [
'#type' => 'select',
'#title' => $this
->t('Nav style modifiers'),
'#description' => $this
->t('Select which nav style to use.'),
'#options' => [
'uk-nav-default' => $this
->t('Default'),
'uk-nav-primary' => $this
->t('Primary'),
],
'#empty_value' => '',
'#default_value' => UIkitComponents::getNavStyleModifier($this->entity
->id()),
'#weight' => -5,
'#states' => [
'visible' => [
[
':input[name="menu_style"]' => [
'value' => 'uk-nav',
],
],
],
],
];
$form['menu_style_nav_center_modifier'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Nav center modifier'),
'#description' => $this
->t('Select to center nav items.'),
'#default_value' => UIkitComponents::getNavCenterModifier($this->entity
->id()),
'#weight' => -3,
'#states' => [
'visible' => [
[
':input[name="menu_style"]' => [
'value' => 'uk-nav',
],
],
],
],
];
$form['menu_style_wrapper_widths'] = [
'#type' => 'textfield',
'#title' => $this
->t('Menu wrapper width classes'),
'#description' => $this
->t('Enter the <a href=":width" target="_blank">width classes</a>, separated with a space, to wrap the menu in.', $t_args),
'#default_value' => $width_classes,
'#weight' => -2,
];
return $form;
}