You are here

public function EntitySubmenuBlock::blockForm in Entity Submenu Block 8

Overrides SystemMenuBlock::blockForm

File

src/Plugin/Block/EntitySubmenuBlock.php, line 85

Class

EntitySubmenuBlock
Provides an Entity Submenu Block.

Namespace

Drupal\entity_submenu_block\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {
  $form = parent::blockForm($form, $form_state);

  // We don't need the menu levels options from the parent.
  unset($form['menu_levels']);
  $config = $this
    ->getConfiguration();

  // Display non-entities.
  $form['display_non_entities'] = [
    '#title' => $this
      ->t('Display non-entities'),
    '#type' => 'checkbox',
    '#default_value' => $this
      ->getConfigurationValue($config, 'display_non_entities'),
  ];

  // Only display entities with content in current language.
  $form['only_current_language'] = [
    '#type' => 'checkbox',
    '#title' => t('Only display entities with content in current language'),
    '#default_value' => $this
      ->getConfigurationValue($config, 'only_current_language'),
  ];

  // View modes fieldgroup.
  $form['view_modes'] = [
    '#title' => $this
      ->t('View modes'),
    '#description' => $this
      ->t('View modes to be used when submenu items are displayed as content entities'),
    '#type' => 'fieldgroup',
    '#process' => [
      [
        get_class(),
        'processFieldSets',
      ],
    ],
  ];

  // A select list of view modes for each entity type.
  foreach ($this
    ->getEntityTypes() as $entity_type) {
    $field = 'view_mode_' . $entity_type;
    $view_modes = $this->entityDisplayRepository
      ->getViewModeOptions($entity_type);
    $form['view_modes'][$field] = [
      '#title' => $this->entityTypeManager
        ->getDefinition($entity_type)
        ->getLabel(),
      '#type' => 'select',
      '#options' => $view_modes,
      '#default_value' => $this
        ->getConfigurationValue($config, $field, array_keys($view_modes)),
    ];
  }
  return $form;
}