function SystemMenuBlock::blockForm

Same name and namespace in other branches
  1. 8.9.x core/modules/system/src/Plugin/Block/SystemMenuBlock.php \Drupal\system\Plugin\Block\SystemMenuBlock::blockForm()
  2. 10 core/modules/system/src/Plugin/Block/SystemMenuBlock.php \Drupal\system\Plugin\Block\SystemMenuBlock::blockForm()
  3. 11.x core/modules/system/src/Plugin/Block/SystemMenuBlock.php \Drupal\system\Plugin\Block\SystemMenuBlock::blockForm()

Overrides BlockPluginTrait::blockForm

File

core/modules/system/src/Plugin/Block/SystemMenuBlock.php, line 79

Class

SystemMenuBlock
Provides a generic Menu block.

Namespace

Drupal\system\Plugin\Block

Code

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'],
        '#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.'),
    ];
    return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.