3 namespace Drupal\Core\Menu;
5 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
6 use Symfony\Component\DependencyInjection\ContainerInterface;
9 * Provides a default implementation for menu link plugins.
11 class MenuLinkDefault extends MenuLinkBase implements ContainerFactoryPluginInterface {
16 protected $overrideAllowed = [
25 * The static menu link service used to store updates to weight/parent etc.
27 * @var \Drupal\Core\Menu\StaticMenuLinkOverridesInterface
29 protected $staticOverride;
32 * Constructs a new MenuLinkDefault.
34 * @param array $configuration
35 * A configuration array containing information about the plugin instance.
36 * @param string $plugin_id
37 * The plugin_id for the plugin instance.
38 * @param mixed $plugin_definition
39 * The plugin implementation definition.
40 * @param \Drupal\Core\Menu\StaticMenuLinkOverridesInterface $static_override
41 * The static override storage.
43 public function __construct(array $configuration, $plugin_id, $plugin_definition, StaticMenuLinkOverridesInterface $static_override) {
44 parent::__construct($configuration, $plugin_id, $plugin_definition);
46 $this->staticOverride = $static_override;
52 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
57 $container->get('menu_link.static.overrides')
64 public function getTitle() {
65 return (string) $this->pluginDefinition['title'];
71 public function getDescription() {
72 return (string) $this->pluginDefinition['description'];
78 public function isResettable() {
79 // The link can be reset if it has an override.
80 return (bool) $this->staticOverride->loadOverride($this->getPluginId());
86 public function updateLink(array $new_definition_values, $persist) {
87 // Filter the list of updates to only those that are allowed.
88 $overrides = array_intersect_key($new_definition_values, $this->overrideAllowed);
89 // Update the definition.
90 $this->pluginDefinition = $overrides + $this->getPluginDefinition();
92 // Always save the menu name as an override to avoid defaulting to tools.
93 $overrides['menu_name'] = $this->pluginDefinition['menu_name'];
94 $this->staticOverride->saveOverride($this->getPluginId(), $this->pluginDefinition);
96 return $this->pluginDefinition;