3 namespace Drupal\Core\Menu;
5 use Drupal\Component\Plugin\Exception\PluginException;
6 use Drupal\Core\Cache\Cache;
7 use Drupal\Core\Plugin\PluginBase;
11 * Defines a base menu link class.
13 abstract class MenuLinkBase extends PluginBase implements MenuLinkInterface {
16 * The list of definition values where an override is allowed.
18 * The keys are definition names. The values are ignored.
22 protected $overrideAllowed = [];
27 public function getWeight() {
28 // By default the weight is 0.
29 if (!isset($this->pluginDefinition['weight'])) {
30 $this->pluginDefinition['weight'] = 0;
32 return $this->pluginDefinition['weight'];
38 public function getMenuName() {
39 return $this->pluginDefinition['menu_name'];
45 public function getProvider() {
46 return $this->pluginDefinition['provider'];
52 public function getParent() {
53 return $this->pluginDefinition['parent'];
59 public function isEnabled() {
60 return (bool) $this->pluginDefinition['enabled'];
66 public function isExpanded() {
67 return (bool) $this->pluginDefinition['expanded'];
73 public function isResettable() {
80 public function isTranslatable() {
81 return (bool) $this->getTranslateRoute();
87 public function isDeletable() {
88 return (bool) $this->getDeleteRoute();
94 public function getOptions() {
95 return $this->pluginDefinition['options'] ?: [];
101 public function getMetaData() {
102 return $this->pluginDefinition['metadata'] ?: [];
108 public function getRouteName() {
109 return isset($this->pluginDefinition['route_name']) ? $this->pluginDefinition['route_name'] : '';
115 public function getRouteParameters() {
116 return isset($this->pluginDefinition['route_parameters']) ? $this->pluginDefinition['route_parameters'] : [];
122 public function getUrlObject($title_attribute = TRUE) {
123 $options = $this->getOptions();
124 if ($title_attribute && $description = $this->getDescription()) {
125 $options['attributes']['title'] = $description;
127 if (empty($this->pluginDefinition['url'])) {
128 return new Url($this->getRouteName(), $this->getRouteParameters(), $options);
131 return Url::fromUri($this->pluginDefinition['url'], $options);
138 public function getFormClass() {
139 return $this->pluginDefinition['form_class'];
145 public function getDeleteRoute() {
152 public function getEditRoute() {
159 public function getTranslateRoute() {
166 public function deleteLink() {
167 throw new PluginException("Menu link plugin with ID '{$this->getPluginId()}' does not support deletion");
173 public function getCacheMaxAge() {
174 return Cache::PERMANENT;
180 public function getCacheContexts() {
187 public function getCacheTags() {