class LocalTaskDefault

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

Default object used for LocalTaskPlugins.

Hierarchy

Expanded class hierarchy of LocalTaskDefault

6 files declare their use of LocalTaskDefault
ConfigTranslationLocalTask.php in core/modules/config_translation/src/Plugin/Menu/LocalTask/ConfigTranslationLocalTask.php
LocalTaskDefaultTest.php in core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php
Contains \Drupal\Tests\Core\Menu\LocalTaskDefaultTest.
TestTasksSettingsSub1.php in core/modules/system/tests/modules/menu_test/src/Plugin/Menu/LocalTask/TestTasksSettingsSub1.php
TestTaskWithUserInput.php in core/modules/system/tests/modules/menu_test/src/Plugin/Menu/LocalTask/TestTaskWithUserInput.php
UnapprovedComments.php in core/modules/comment/src/Plugin/Menu/LocalTask/UnapprovedComments.php

... See full list

3 string references to 'LocalTaskDefault'
field_ui.links.task.yml in core/modules/field_ui/field_ui.links.task.yml
core/modules/field_ui/field_ui.links.task.yml
search.links.task.yml in core/modules/search/search.links.task.yml
core/modules/search/search.links.task.yml
views.links.task.yml in core/modules/views/views.links.task.yml
core/modules/views/views.links.task.yml

File

core/lib/Drupal/Core/Menu/LocalTaskDefault.php, line 15

Namespace

Drupal\Core\Menu
View source
class LocalTaskDefault extends PluginBase implements LocalTaskInterface, CacheableDependencyInterface {
    use DependencySerializationTrait;
    
    /**
     * The route provider to load routes by name.
     *
     * @var \Drupal\Core\Routing\RouteProviderInterface
     */
    protected $routeProvider;
    
    /**
     * TRUE if this plugin is forced active for options attributes.
     *
     * @var bool
     */
    protected $active = FALSE;
    
    /**
     * {@inheritdoc}
     */
    public function getRouteName() {
        return $this->pluginDefinition['route_name'];
    }
    
    /**
     * {@inheritdoc}
     */
    public function getRouteParameters(RouteMatchInterface $route_match) {
        $route_parameters = isset($this->pluginDefinition['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 getTitle(Request $request = NULL) {
        // The title from YAML file discovery may be a TranslatableMarkup object.
        return (string) $this->pluginDefinition['title'];
    }
    
    /**
     * Returns the weight of the local task.
     *
     * @return int
     *   The weight of the task. If not defined in the annotation returns 0 by
     *   default or -10 for the root tab.
     */
    public function getWeight() {
        // By default the weight is 0, or -10 for the root tab.
        if (!isset($this->pluginDefinition['weight'])) {
            if ($this->pluginDefinition['base_route'] == $this->pluginDefinition['route_name']) {
                $this->pluginDefinition['weight'] = -10;
            }
            else {
                $this->pluginDefinition['weight'] = 0;
            }
        }
        return (int) $this->pluginDefinition['weight'];
    }
    
    /**
     * {@inheritdoc}
     */
    public function getOptions(RouteMatchInterface $route_match) {
        $options = $this->pluginDefinition['options'];
        if ($this->active) {
            if (empty($options['attributes']['class']) || !in_array('is-active', $options['attributes']['class'])) {
                $options['attributes']['class'][] = 'is-active';
            }
        }
        return (array) $options;
    }
    
    /**
     * {@inheritdoc}
     */
    public function setActive($active = TRUE) {
        $this->active = $active;
        return $this;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getActive() {
        return $this->active;
    }
    
    /**
     * Returns the route provider.
     *
     * @return \Drupal\Core\Routing\RouteProviderInterface
     *   The route provider.
     */
    protected function routeProvider() {
        if (!$this->routeProvider) {
            $this->routeProvider = \Drupal::service('router.route_provider');
        }
        return $this->routeProvider;
    }
    
    /**
     * {@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 Modifiers Object type Summary Overriden Title Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
LocalTaskDefault::$active protected property TRUE if this plugin is forced active for options attributes.
LocalTaskDefault::$routeProvider protected property The route provider to load routes by name.
LocalTaskDefault::getActive public function Gets the active status. Overrides LocalTaskInterface::getActive
LocalTaskDefault::getCacheContexts public function The cache contexts associated with this object. Overrides CacheableDependencyInterface::getCacheContexts
LocalTaskDefault::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyInterface::getCacheMaxAge
LocalTaskDefault::getCacheTags public function The cache tags associated with this object. Overrides CacheableDependencyInterface::getCacheTags 1
LocalTaskDefault::getOptions public function Returns options for rendering a link to the local task. Overrides LocalTaskInterface::getOptions
LocalTaskDefault::getRouteName public function Get the route name from the settings. Overrides LocalTaskInterface::getRouteName
LocalTaskDefault::getRouteParameters public function Returns the route parameters needed to render a link for the local task. Overrides LocalTaskInterface::getRouteParameters 1
LocalTaskDefault::getTitle public function Returns the localized title to be shown for this tab. Overrides LocalTaskInterface::getTitle 4
LocalTaskDefault::getWeight public function Returns the weight of the local task. Overrides LocalTaskInterface::getWeight
LocalTaskDefault::routeProvider protected function Returns the route provider.
LocalTaskDefault::setActive public function Sets the active status. Overrides LocalTaskInterface::setActive
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 public function Determines if the plugin is configurable.
PluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. 6

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