class LocalActionDefault

Same name in other branches
  1. 9 core/lib/Drupal/Core/Menu/LocalActionDefault.php \Drupal\Core\Menu\LocalActionDefault
  2. 8.9.x core/lib/Drupal/Core/Menu/LocalActionDefault.php \Drupal\Core\Menu\LocalActionDefault
  3. 10 core/lib/Drupal/Core/Menu/LocalActionDefault.php \Drupal\Core\Menu\LocalActionDefault

Provides a default implementation for local action plugins.

Hierarchy

Expanded class hierarchy of LocalActionDefault

8 files declare their use of LocalActionDefault
BlockContentAddLocalAction.php in core/modules/block_content/src/Plugin/Menu/LocalAction/BlockContentAddLocalAction.php
DisplayModeLocalAction.php in core/modules/field_ui/src/DisplayModeLocalAction.php
LocalActionDefaultTest.php in core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php
MenuLinkAdd.php in core/modules/menu_ui/src/Plugin/Menu/LocalAction/MenuLinkAdd.php
TestLocalAction.php in core/modules/system/tests/modules/menu_test/src/Plugin/Menu/LocalAction/TestLocalAction.php

... See full list

2 string references to 'LocalActionDefault'
field_ui.links.action.yml in core/modules/field_ui/field_ui.links.action.yml
core/modules/field_ui/field_ui.links.action.yml
menu_test.links.action.yml in core/modules/system/tests/modules/menu_test/menu_test.links.action.yml
core/modules/system/tests/modules/menu_test/menu_test.links.action.yml

File

core/lib/Drupal/Core/Menu/LocalActionDefault.php, line 18

Namespace

Drupal\Core\Menu
View source
class LocalActionDefault extends PluginBase implements LocalActionInterface, ContainerFactoryPluginInterface, CacheableDependencyInterface {
    use DependencySerializationTrait;
    
    /**
     * The route provider to load routes by name.
     *
     * @var \Drupal\Core\Routing\RouteProviderInterface
     */
    protected $routeProvider;
    
    /**
     * Constructs a LocalActionDefault object.
     *
     * @param array $configuration
     *   A configuration array containing information about the plugin instance.
     * @param string $plugin_id
     *   The plugin ID for the plugin instance.
     * @param mixed $plugin_definition
     *   The plugin implementation definition.
     * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
     *   The route provider to load routes by name.
     */
    public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteProviderInterface $route_provider) {
        parent::__construct($configuration, $plugin_id, $plugin_definition);
        $this->routeProvider = $route_provider;
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
        return new static($configuration, $plugin_id, $plugin_definition, $container->get('router.route_provider'));
    }
    
    /**
     * {@inheritdoc}
     */
    public function getRouteName() {
        return $this->pluginDefinition['route_name'];
    }
    
    /**
     * {@inheritdoc}
     */
    public function getTitle(?Request $request = NULL) {
        // Subclasses may pull in the request or specific attributes as parameters.
        // The title from YAML file discovery may be a TranslatableMarkup object.
        return (string) $this->pluginDefinition['title'];
    }
    
    /**
     * {@inheritdoc}
     */
    public function getWeight() {
        return $this->pluginDefinition['weight'];
    }
    
    /**
     * {@inheritdoc}
     */
    public function getRouteParameters(RouteMatchInterface $route_match) {
        $route_parameters = $this->pluginDefinition['route_parameters'] ?? [];
        $route = $this->routeProvider
            ->getRouteByName($this->getRouteName());
        $variables = $route->compile()
            ->getVariables();
        // Normally the \Drupal\Core\ParamConverter\ParamConverterManager has
        // run, and the route parameters have been upcast. The original values can
        // be retrieved from the raw parameters. For example, if the route's path is
        // /filter/tips/{filter_format} and the path is /filter/tips/plain_text then
        // $raw_parameters->get('filter_format') == 'plain_text'. Parameters that
        // are not represented in the route path as slugs might be added by a route
        // enhancer and will not be present in the raw parameters.
        $raw_parameters = $route_match->getRawParameters();
        $parameters = $route_match->getParameters();
        foreach ($variables as $name) {
            if (isset($route_parameters[$name])) {
                continue;
            }
            if ($raw_parameters->has($name)) {
                $route_parameters[$name] = $raw_parameters->get($name);
            }
            elseif ($parameters->has($name)) {
                $route_parameters[$name] = $parameters->get($name);
            }
        }
        // The UrlGenerator will throw an exception if expected parameters are
        // missing. This method should be overridden if that is possible.
        return $route_parameters;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getOptions(RouteMatchInterface $route_match) {
        return (array) $this->pluginDefinition['options'];
    }
    
    /**
     * {@inheritdoc}
     */
    public function getCacheTags() {
        if (!isset($this->pluginDefinition['cache_tags'])) {
            return [];
        }
        return $this->pluginDefinition['cache_tags'];
    }
    
    /**
     * {@inheritdoc}
     */
    public function getCacheContexts() {
        if (!isset($this->pluginDefinition['cache_contexts'])) {
            return [];
        }
        return $this->pluginDefinition['cache_contexts'];
    }
    
    /**
     * {@inheritdoc}
     */
    public function getCacheMaxAge() {
        if (!isset($this->pluginDefinition['cache_max_age'])) {
            return Cache::PERMANENT;
        }
        return $this->pluginDefinition['cache_max_age'];
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
LocalActionDefault::$routeProvider protected property The route provider to load routes by name.
LocalActionDefault::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 3
LocalActionDefault::getCacheContexts public function The cache contexts associated with this object. Overrides CacheableDependencyInterface::getCacheContexts
LocalActionDefault::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyInterface::getCacheMaxAge
LocalActionDefault::getCacheTags public function The cache tags associated with this object. Overrides CacheableDependencyInterface::getCacheTags
LocalActionDefault::getOptions public function Returns options for rendering a link for the local action. Overrides LocalActionInterface::getOptions 3
LocalActionDefault::getRouteName public function Get the route name from the settings. Overrides LocalActionInterface::getRouteName
LocalActionDefault::getRouteParameters public function Returns the route parameters needed to render a link for the local action. Overrides LocalActionInterface::getRouteParameters
LocalActionDefault::getTitle public function Returns the localized title to be shown for this action. Overrides LocalActionInterface::getTitle 4
LocalActionDefault::getWeight public function Returns the weight for the local action. Overrides LocalActionInterface::getWeight
LocalActionDefault::__construct public function Constructs a LocalActionDefault object. Overrides PluginBase::__construct 3
PluginBase::$configuration protected property Configuration information passed into the plugin.
PluginBase::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin ID.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
PluginBase::getPluginId public function Gets the plugin ID of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable Deprecated public function Determines if the plugin is configurable.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.