function SystemMenuBlock::blockForm
Same name and namespace in other branches
- 11.x core/modules/system/src/Plugin/Block/SystemMenuBlock.php \Drupal\system\Plugin\Block\SystemMenuBlock::blockForm()
- 10 core/modules/system/src/Plugin/Block/SystemMenuBlock.php \Drupal\system\Plugin\Block\SystemMenuBlock::blockForm()
- 9 core/modules/system/src/Plugin/Block/SystemMenuBlock.php \Drupal\system\Plugin\Block\SystemMenuBlock::blockForm()
- 8.9.x core/modules/system/src/Plugin/Block/SystemMenuBlock.php \Drupal\system\Plugin\Block\SystemMenuBlock::blockForm()
Overrides BlockPluginTrait::blockForm
1 method overrides SystemMenuBlock::blockForm()
- NavigationMenuBlock::blockForm in core/
modules/ navigation/ src/ Plugin/ Block/ NavigationMenuBlock.php
File
-
core/
modules/ system/ src/ Plugin/ Block/ SystemMenuBlock.php, line 68
Class
- SystemMenuBlock
- Provides a generic Menu block.
Namespace
Drupal\system\Plugin\BlockCode
public function blockForm($form, FormStateInterface $form_state) {
$config = $this->configuration;
$defaults = $this->defaultConfiguration();
$form['menu_levels'] = [
'#type' => 'details',
'#title' => $this->t('Menu levels'),
// Open if not set to defaults.
'#open' => $defaults['level'] !== $config['level'] || $defaults['depth'] !== $config['depth'],
'#process' => [
[
self::class,
'processMenuLevelParents',
],
],
];
$options = range(0, $this->menuTree
->maxDepth());
unset($options[0]);
$form['menu_levels']['level'] = [
'#type' => 'select',
'#title' => $this->t('Initial visibility level'),
'#default_value' => $config['level'],
'#options' => $options,
'#description' => $this->t('The menu is only visible if the menu link for the current page is at this level or below it. Use level 1 to always display this menu.'),
'#required' => TRUE,
];
$options[0] = $this->t('Unlimited');
$form['menu_levels']['depth'] = [
'#type' => 'select',
'#title' => $this->t('Number of levels to display'),
'#default_value' => $config['depth'] ?? 0,
'#options' => $options,
'#description' => $this->t('This maximum number includes the initial level.'),
'#required' => TRUE,
];
$form['menu_levels']['expand_all_items'] = [
'#type' => 'checkbox',
'#title' => $this->t('Expand all menu links'),
'#default_value' => !empty($config['expand_all_items']),
'#description' => $this->t('Override the option found on each menu link used for expanding children and instead display the whole menu tree as expanded.'),
];
// When only the first level of links are shown, or if all links are
// expanded, the active trail logic can be skipped.
$state_conditions = [
// When the menu level starts at anything other than 1.
[
':input[name="settings[level]"]' => [
'!value' => '1',
],
],
'or',
// When links aren't all expanded, and more than one level of links are
// shown.
[
'input[name="settings[expand_all_items]"]' => [
'checked' => FALSE,
],
':input[name="settings[depth]"]' => [
'!value' => '1',
],
],
];
// The 'add_active_trail_class' checkbox value is the inverse of the
// 'ignore_active_trail configuration value. This is because the positive
// statement is easier to explain in the UI, but the negative statement is
// easier to implement in the API.
$form['menu_levels']['add_active_trail_class'] = [
'#type' => 'checkbox',
'#title' => $this->t('Add a CSS class to ancestors of the current page'),
'#default_value' => empty($config['ignore_active_trail']),
'#description' => $this->t('Adds a CSS class to parent menu links when the current page is in the menu. This feature has a performance impact and should only be enabled when the menu appearance should differ based on the current page.'),
'#states' => [
'required' => $state_conditions,
],
];
return $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.