You are here

public function GroupMenuBlock::blockForm in Group Content Menu 8

Overrides BlockPluginTrait::blockForm

File

src/Plugin/Block/GroupMenuBlock.php, line 99

Class

GroupMenuBlock
Provides a generic Menu block.

Namespace

Drupal\group_content_menu\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' => [
      [
        get_class(),
        'processMenuLevelParents',
      ],
    ],
  ];
  $options = range(0, $this->menuTree
    ->maxDepth());
  unset($options[0]);
  $form['menu_levels']['level'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Initial menu level'),
    '#default_value' => $config['level'],
    '#options' => $options,
    '#description' => $this
      ->t('The menu will only be visible if the menu item for the current page is at or below the selected starting level. Select level 1 to always keep this menu visible.'),
    '#required' => TRUE,
  ];
  $options[0] = $this
    ->t('Unlimited');
  $form['menu_levels']['depth'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Maximum number of menu levels to display'),
    '#default_value' => $config['depth'],
    '#options' => $options,
    '#description' => $this
      ->t('The maximum number of menu levels to show, starting from the initial menu level. For example: with an initial level 2 and a maximum number of 3, menu levels 2, 3 and 4 can be displayed.'),
    '#required' => TRUE,
  ];
  $form['menu_levels']['expand_all_items'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Expand all menu items'),
    '#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;
}