diff --git a/core/modules/menu/lib/Drupal/menu/Plugin/Block/MenuLevelBlock.php b/core/modules/menu/lib/Drupal/menu/Plugin/Block/MenuLevelBlock.php new file mode 100644 index 0000000..bbc4895 --- /dev/null +++ b/core/modules/menu/lib/Drupal/menu/Plugin/Block/MenuLevelBlock.php @@ -0,0 +1,135 @@ +configFactory = $config_factory; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('config.factory') + ); + } + + /** + * {@inheritdoc} + */ + public function defaultConfiguration() { + return array( + 'menu' => 'main', + 'level' => 0, + ); + } + + /** + * {@inheritdoc} + */ + public function blockForm($form, &$form_state) { + + $form['menu'] = array( + '#type' => 'select', + '#title' => $this->t('Source menu'), + '#default_value' => $this->configuration['menu'], + '#options' => menu_get_menus(), + '#required' => TRUE, + ); + $form['level'] = array( + '#type' => 'select', + '#title' => $this->t('Starting level'), + '#default_value' => $this->configuration['level'], + '#options' => array(0,1,2,3,4,5,6,7,8), + '#required' => TRUE, + ); + + return $form; + } + + /** + * {@inheritdoc} + */ + public function blockSubmit($form, &$form_state) { + $this->configuration['menu'] = $form_state['values']['menu']; + $this->configuration['level'] = $form_state['values']['level']; + } + + /** + * {@inheritdoc} + */ + public function build() { + $menu_name = $this->configuration['menu']; + $level = $this->configuration['level']; + + $links = menu_navigation_links($menu_name, $level); + // Do not output this entire block if there are no visible/accessible + // links. Filter the links to remove those with #access set to FALSE. + array_filter($links, function($link){ + if (isset($link['#access']) && $link['#access'] === FALSE) { + return FALSE; + } + return TRUE; + }); + if (empty($links)) { + return array(); + } + + $build = array( + '#theme' => 'links', + '#links' => $links, + ); + if (!empty($this->configuration['id'])) { + $build['#attributes']['id'] = drupal_html_id($this->configuration['id']); + } + + return $build; + } + +}