MenuLinkBase.php in Drupal 8
File
core/lib/Drupal/Core/Menu/MenuLinkBase.php
View source
<?php
namespace Drupal\Core\Menu;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Url;
abstract class MenuLinkBase extends PluginBase implements MenuLinkInterface {
protected $overrideAllowed = [];
public function getWeight() {
if (!isset($this->pluginDefinition['weight'])) {
$this->pluginDefinition['weight'] = 0;
}
return $this->pluginDefinition['weight'];
}
public function getMenuName() {
return $this->pluginDefinition['menu_name'];
}
public function getProvider() {
return $this->pluginDefinition['provider'];
}
public function getParent() {
return $this->pluginDefinition['parent'];
}
public function isEnabled() {
return (bool) $this->pluginDefinition['enabled'];
}
public function isExpanded() {
return (bool) $this->pluginDefinition['expanded'];
}
public function isResettable() {
return FALSE;
}
public function isTranslatable() {
return (bool) $this
->getTranslateRoute();
}
public function isDeletable() {
return (bool) $this
->getDeleteRoute();
}
public function getOptions() {
return $this->pluginDefinition['options'] ?: [];
}
public function getMetaData() {
return $this->pluginDefinition['metadata'] ?: [];
}
public function getRouteName() {
return isset($this->pluginDefinition['route_name']) ? $this->pluginDefinition['route_name'] : '';
}
public function getRouteParameters() {
return isset($this->pluginDefinition['route_parameters']) ? $this->pluginDefinition['route_parameters'] : [];
}
public function getUrlObject($title_attribute = TRUE) {
$options = $this
->getOptions();
if ($title_attribute && ($description = $this
->getDescription())) {
$options['attributes']['title'] = $description;
}
if (empty($this->pluginDefinition['url'])) {
return new Url($this
->getRouteName(), $this
->getRouteParameters(), $options);
}
else {
return Url::fromUri($this->pluginDefinition['url'], $options);
}
}
public function getFormClass() {
return $this->pluginDefinition['form_class'];
}
public function getDeleteRoute() {
return NULL;
}
public function getEditRoute() {
return NULL;
}
public function getTranslateRoute() {
return NULL;
}
public function deleteLink() {
throw new PluginException("Menu link plugin with ID '{$this->getPluginId()}' does not support deletion");
}
public function getCacheMaxAge() {
return Cache::PERMANENT;
}
public function getCacheContexts() {
return [];
}
public function getCacheTags() {
return [];
}
}