LocalActionsBlock.php in Drupal 8
File
core/lib/Drupal/Core/Menu/Plugin/Block/LocalActionsBlock.php
View source
<?php
namespace Drupal\Core\Menu\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Menu\LocalActionManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Routing\RouteMatchInterface;
class LocalActionsBlock extends BlockBase implements ContainerFactoryPluginInterface {
protected $localActionManager;
protected $routeMatch;
public function __construct(array $configuration, $plugin_id, $plugin_definition, LocalActionManagerInterface $local_action_manager, RouteMatchInterface $route_match) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->localActionManager = $local_action_manager;
$this->routeMatch = $route_match;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('plugin.manager.menu.local_action'), $container
->get('current_route_match'));
}
public function defaultConfiguration() {
return [
'label_display' => FALSE,
];
}
public function build() {
$route_name = $this->routeMatch
->getRouteName();
$local_actions = $this->localActionManager
->getActionsForRoute($route_name);
return $local_actions;
}
}