diff --git a/core/includes/menu.inc b/core/includes/menu.inc index d578499..1c6d6fa 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -177,16 +177,6 @@ function menu_secondary_local_tasks() { } /** - * Returns the rendered local actions at the current level. - */ -function menu_get_local_actions() { - $links = menu_local_tasks(); - $route_name = Drupal::routeMatch()->getRouteName(); - $manager = \Drupal::service('plugin.manager.menu.local_action'); - return $manager->getActionsForRoute($route_name) + $links['actions']; -} - -/** * Returns the router path, or the path for a default local task's parent. */ function menu_tab_root_path() { diff --git a/core/lib/Drupal/Core/Menu/LocalActionManager.php b/core/lib/Drupal/Core/Menu/LocalActionManager.php index 208075c..b2ea312 100644 --- a/core/lib/Drupal/Core/Menu/LocalActionManager.php +++ b/core/lib/Drupal/Core/Menu/LocalActionManager.php @@ -174,6 +174,7 @@ public function getActionsForRoute($route_appears) { foreach ($this->instances[$route_appears] as $plugin_id => $plugin) { $route_name = $plugin->getRouteName(); $route_parameters = $plugin->getRouteParameters($this->routeMatch); + $access = $this->accessManager->checkNamedRoute($route_name, $route_parameters, $this->account, TRUE); $links[$plugin_id] = array( '#theme' => 'menu_local_action', '#link' => array( @@ -181,9 +182,10 @@ public function getActionsForRoute($route_appears) { 'url' => Url::fromRoute($route_name, $route_parameters), 'localized_options' => $plugin->getOptions($this->routeMatch), ), - '#access' => $this->accessManager->checkNamedRoute($route_name, $route_parameters, $this->account), + '#access' => $access->isAllowed(), '#weight' => $plugin->getWeight(), ); + \Drupal::service('renderer')->addDependency($links, $access); } return $links; } diff --git a/core/lib/Drupal/Core/Menu/LocalTaskManager.php b/core/lib/Drupal/Core/Menu/LocalTaskManager.php index 2ef5de1..afbd50d 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskManager.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskManager.php @@ -305,8 +305,8 @@ public function getTasksBuild($current_route_name) { $route_parameters = $child->getRouteParameters($this->routeMatch); // Find out whether the user has access to the task. - $access = $this->accessManager->checkNamedRoute($route_name, $route_parameters, $this->account); - if ($access) { + $access = $this->accessManager->checkNamedRoute($route_name, $route_parameters, $this->account, TRUE); + if ($access->isAllowed()) { $active = $this->isRouteActive($current_route_name, $route_name, $route_parameters); // The plugin may have been set active in getLocalTasksForRoute() if @@ -327,6 +327,7 @@ public function getTasksBuild($current_route_name) { '#access' => $access, ); } + \Drupal::service('renderer')->addDependency($build, $access); } } return $build; diff --git a/core/modules/system/src/Plugin/Block/SystemPageActionsBlock.php b/core/modules/system/src/Plugin/Block/SystemPageActionsBlock.php index 3d5a9e0..44f7d0d 100644 --- a/core/modules/system/src/Plugin/Block/SystemPageActionsBlock.php +++ b/core/modules/system/src/Plugin/Block/SystemPageActionsBlock.php @@ -10,14 +10,14 @@ use Drupal\Core\Block\BlockBase; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Menu\LocalActionManager; +use Drupal\Core\Menu\LocalActionManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RequestStack; /** - * Provides a block to display the page local actions. + * Provides a block to display the page actions. * * @Block( * id = "system_page_actions_block", @@ -27,16 +27,16 @@ class SystemPageActionsBlock extends BlockBase implements ContainerFactoryPluginInterface { /** - * Stores the configuration factory. + * The configuration factory. * * @var \Drupal\Core\Config\ConfigFactoryInterface */ protected $configFactory; /** - * A local action manger. + * The local action manger. * - * @var \Drupal\Core\Menu\LocalActionManager + * @var \Drupal\Core\Menu\LocalActionManagerInterface */ protected $localActionManager; @@ -57,13 +57,13 @@ class SystemPageActionsBlock extends BlockBase implements ContainerFactoryPlugin * @param mixed $plugin_definition * The plugin implementation definition. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The factory for configuration objects. - * @param \Drupal\Core\Menu\LocalActionManager $local_action_manager - * The local action manager. + * The configuration factory. + * @param \Drupal\Core\Menu\LocalActionManagerInterface $local_action_manager + * A local action manager. * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack * The request stack object. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, LocalActionManager $local_action_manager, RequestStack $request_stack) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, LocalActionManagerInterface $local_action_manager, RequestStack $request_stack) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->configFactory = $config_factory; $this->localActionManager = $local_action_manager; @@ -104,7 +104,7 @@ public function build() { return FALSE; } - $build['action_links'] = ['#markup' => $action_links]; + $build['action_links'] = $action_links; return $build; } @@ -126,10 +126,8 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta /** * {@inheritdoc} */ - public function isCacheable() { - // The "Page Actions" block is never cacheable, because its contents depends - // on access checks, which are currently uncacheable. - // @todo Make cacheable once https://drupal.org/node/2287071 lands. + public function getCacheMaxAge() { + // @todo Make me cacheable now that https://drupal.org/node/2287071 has landed. return FALSE; } diff --git a/core/modules/system/src/Plugin/Block/SystemPageTabsBlock.php b/core/modules/system/src/Plugin/Block/SystemPageTabsBlock.php index ad240d4..0ec09ba 100644 --- a/core/modules/system/src/Plugin/Block/SystemPageTabsBlock.php +++ b/core/modules/system/src/Plugin/Block/SystemPageTabsBlock.php @@ -24,7 +24,7 @@ class SystemPageTabsBlock extends BlockBase implements ContainerFactoryPluginInterface { /** - * Stores the configuration factory. + * The configuration factory. * * @var \Drupal\Core\Config\ConfigFactoryInterface */ @@ -40,7 +40,7 @@ class SystemPageTabsBlock extends BlockBase implements ContainerFactoryPluginInt * @param mixed $plugin_definition * The plugin implementation definition. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The factory for configuration objects. + * The configuration factory. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory) { parent::__construct($configuration, $plugin_id, $plugin_definition); @@ -74,7 +74,7 @@ public function build() { if (empty($tabs)) { return FALSE; } - $build['tabs']['#markup'] = menu_local_tabs(); + $build['tabs'] = $tabs; return $build; } @@ -95,10 +95,8 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta /** * {@inheritdoc} */ - public function isCacheable() { - // The "Page Tabs" block is never cacheable, because its contents depends - // on access checks, which are currently uncacheable. - // @todo Make cacheable once https://drupal.org/node/2287071 lands. + public function getCacheMaxAge() { + // @todo Make cacheable now that https://drupal.org/node/2287071 has landed. return FALSE; } diff --git a/core/modules/system/system.module b/core/modules/system/system.module index a08480c..463bf6c 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -169,14 +169,14 @@ function system_theme() { 'block__system_messages_block' => array( 'base hook' => 'block', ), - 'block__system_page_actions_block' => array( + 'block__system_page_actions_block' => [ 'base hook' => 'block', 'template' => 'block--system-page-actions-block', - ), - 'block__system_page_tabs_block' => array( + ], + 'block__system_page_tabs_block' => [ 'base hook' => 'block', 'template' => 'block--system-page-tabs-block', - ), + ], 'block__system_menu_block' => array( 'render element' => 'elements', 'base hook' => 'block', @@ -788,15 +788,15 @@ function system_preprocess_block(&$variables) { case 'system_page_actions_block': $variables['action_links'] = ''; - if ($variables['content']['action_links']['#markup']) { - $variables['action_links'] = $variables['content']['action_links']['#markup']; + if ($variables['content']['action_links']) { + $variables['action_links'] = $variables['content']['action_links']; } break; case 'system_page_tabs_block': $variables['tabs'] = ''; - if ($variables['content']['tabs']['#markup']) { - $variables['tabs'] = $variables['content']['tabs']['#markup']; + if ($variables['content']['tabs']) { + $variables['tabs'] = $variables['content']['tabs']; } break; diff --git a/core/modules/system/templates/page.html.twig b/core/modules/system/templates/page.html.twig index e317721..2e0aeba 100644 --- a/core/modules/system/templates/page.html.twig +++ b/core/modules/system/templates/page.html.twig @@ -113,9 +113,7 @@ {{ page.tabs }} - {% if page.actions %} - s - {% endif %} + {{ page.actions }} {{ page.content }} {# /.layout-content #} diff --git a/core/themes/bartik/templates/page.html.twig b/core/themes/bartik/templates/page.html.twig index 9585c40..213e342 100644 --- a/core/themes/bartik/templates/page.html.twig +++ b/core/themes/bartik/templates/page.html.twig @@ -128,15 +128,9 @@ {% endif %} {{ title_suffix }} - {% if page.tabs %} - - {% endif %} + {{ page.tabs }} {{ page.help }} - {% if page.actions %} -