class Menu in Sitemap 2.0.x
Same name and namespace in other branches
- 8.2 src/Plugin/Sitemap/Menu.php \Drupal\sitemap\Plugin\Sitemap\Menu
Provides a sitemap for an individual menu.
Plugin annotation
@Sitemap(
id = "menu",
title = @Translation("Menu name"),
description = @Translation("Menu description"),
settings = {
"title" = "",
"show_disabled" = FALSE,
},
deriver = "Drupal\sitemap\Plugin\Derivative\MenuSitemapDeriver",
enabled = FALSE,
menu = "",
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\sitemap\SitemapBase implements SitemapInterface uses StringTranslationTrait
- class \Drupal\sitemap\Plugin\Sitemap\Menu
- class \Drupal\sitemap\SitemapBase implements SitemapInterface uses StringTranslationTrait
Expanded class hierarchy of Menu
File
- src/
Plugin/ Sitemap/ Menu.php, line 26
Namespace
Drupal\sitemap\Plugin\SitemapView source
class Menu extends SitemapBase {
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
// Provide the menu name as the default title.
$menu_name = $this
->getPluginDefinition()['menu'];
$menu = \Drupal::entityTypeManager()
->getStorage('menu')
->load($menu_name);
$form['title']['#default_value'] = $this->settings['title'] ?: $menu
->label();
$form['show_disabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show disabled menu items'),
'#default_value' => isset($this->settings['show_disabled']) ? $this->settings['show_disabled'] : FALSE,
'#description' => $this
->t('When selected, disabled menu links will also be shown.'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function view() {
$menuLinkTree = \Drupal::service('sitemap.menu.link_tree');
$menu_id = $this->pluginDefinition['menu'];
$menu = MenuEntity::load($menu_id);
// Retrieve the expanded tree.
$parameters = new MenuTreeParameters();
if (!$this->settings['show_disabled']) {
$parameters
->onlyEnabledLinks();
}
$tree = $menuLinkTree
->load($menu_id, $parameters);
$manipulators = [
[
'callable' => 'menu.default_tree_manipulators:checkAccess',
],
[
'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
],
];
$tree = $menuLinkTree
->transform($tree, $manipulators);
// Add an alter hook so that other modules can manipulate the
// menu tree prior to rendering.
// @TODO: Document
$alter_mid = preg_replace('/[^a-z0-9_]+/', '_', $menu_id);
\Drupal::moduleHandler()
->alter([
'sitemap_menu_tree',
'sitemap_menu_tree_' . $alter_mid,
], $tree, $menu);
$menu_display = $menuLinkTree
->build($tree);
return [
'#theme' => 'sitemap_item',
'#title' => $this->settings['title'],
'#content' => $menu_display,
'#sitemap' => $this,
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Menu:: |
public | function |
Returns a form to configure settings for the mapping. Overrides SitemapBase:: |
|
Menu:: |
public | function |
Builds a renderable array for a sitemap item. Overrides SitemapInterface:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
SitemapBase:: |
public | property | A Boolean indicating whether this mapping is enabled. | |
SitemapBase:: |
public | property | The name of the provider that owns this mapping. | |
SitemapBase:: |
public | property | An associative array containing the configured settings of the sitemap_map. | |
SitemapBase:: |
protected | property | The global sitemap config. | |
SitemapBase:: |
public | property | The weight of this mapping compared to others in the sitemap. | |
SitemapBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
SitemapBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
|
SitemapBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
SitemapBase:: |
public | function |
Returns the administrative description for this mapping plugin. Overrides SitemapInterface:: |
|
SitemapBase:: |
public | function |
Returns the administrative label for this mapping plugin. Overrides SitemapInterface:: |
|
SitemapBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
SitemapBase:: |
public | function |
Returns a short summary for the current mapping settings. Overrides SitemapInterface:: |
|
SitemapBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |