diff -u b/core/lib/Drupal/Core/Menu/LocalActionManager.php b/core/lib/Drupal/Core/Menu/LocalActionManager.php --- b/core/lib/Drupal/Core/Menu/LocalActionManager.php +++ b/core/lib/Drupal/Core/Menu/LocalActionManager.php @@ -15,6 +15,7 @@ use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator; use Drupal\Core\Plugin\Discovery\YamlDiscovery; use Drupal\Core\Plugin\Factory\ContainerFactory; +use Drupal\Core\Render\RendererInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteProviderInterface; use Drupal\Core\Url; @@ -101,6 +102,13 @@ protected $instances = array(); /** + * The renderer. + * + * @var \Drupal\Core\Render\RendererInterface + */ + protected $renderer; + + /** * Constructs a LocalActionManager object. * * @param \Symfony\Component\HttpKernel\Controller\ControllerResolverInterface $controller_resolver @@ -121,8 +129,10 @@ * The access manager. * @param \Drupal\Core\Session\AccountInterface $account * The current user. + * @param \Drupal\Core\Render\RendererInterface $renderer + * The renderer service. */ - public function __construct(ControllerResolverInterface $controller_resolver, RequestStack $request_stack, RouteMatchInterface $route_match, RouteProviderInterface $route_provider, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, AccessManagerInterface $access_manager, AccountInterface $account) { + public function __construct(ControllerResolverInterface $controller_resolver, RequestStack $request_stack, RouteMatchInterface $route_match, RouteProviderInterface $route_provider, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, AccessManagerInterface $access_manager, AccountInterface $account, RendererInterface $renderer) { // Skip calling the parent constructor, since that assumes annotation-based // discovery. $this->discovery = new YamlDiscovery('links.action', $module_handler->getModuleDirectories()); @@ -135,6 +145,7 @@ $this->accessManager = $access_manager; $this->moduleHandler = $module_handler; $this->account = $account; + $this->renderer = $renderer; $this->alterInfo('menu_local_actions'); $this->setCacheBackend($cache_backend, 'local_action_plugins:' . $language_manager->getCurrentLanguage()->getId(), array('local_action')); } @@ -174,6 +185,7 @@ 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 +193,10 @@ 'url' => Url::fromRoute($route_name, $route_parameters), 'localized_options' => $plugin->getOptions($this->routeMatch), ), - '#access' => $this->accessManager->checkNamedRoute($route_name, $route_parameters, $this->account, TRUE), + '#access' => $access->isAllowed(), '#weight' => $plugin->getWeight(), ); + $this->renderer->addCacheableDependency($links, $access); } return $links; diff -u b/core/lib/Drupal/Core/Menu/LocalTaskManager.php b/core/lib/Drupal/Core/Menu/LocalTaskManager.php --- b/core/lib/Drupal/Core/Menu/LocalTaskManager.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskManager.php @@ -20,6 +20,7 @@ use Drupal\Core\Plugin\Factory\ContainerFactory; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteProviderInterface; +use Drupal\Core\Render\RendererInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; use Symfony\Component\HttpFoundation\RequestStack; @@ -103,6 +104,13 @@ protected $account; /** + * The renderer. + * + * @var \Drupal\Core\Render\RendererInterface + */ + protected $renderer; + + /** * Constructs a \Drupal\Core\Menu\LocalTaskManager object. * * @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver @@ -123,8 +131,10 @@ * The access manager. * @param \Drupal\Core\Session\AccountInterface $account * The current user. + * @param \Drupal\Core\Render\RendererInterface $renderer + * The renderer service. */ - public function __construct(ControllerResolverInterface $controller_resolver, RequestStack $request_stack, RouteMatchInterface $route_match, RouteProviderInterface $route_provider, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, AccessManagerInterface $access_manager, AccountInterface $account) { + public function __construct(ControllerResolverInterface $controller_resolver, RequestStack $request_stack, RouteMatchInterface $route_match, RouteProviderInterface $route_provider, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, AccessManagerInterface $access_manager, AccountInterface $account, RendererInterface $renderer) { $this->discovery = new YamlDiscovery('links.task', $module_handler->getModuleDirectories()); $this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery); $this->factory = new ContainerFactory($this, '\Drupal\Core\Menu\LocalTaskInterface'); @@ -135,6 +145,7 @@ $this->accessManager = $access_manager; $this->account = $account; $this->moduleHandler = $module_handler; + $this->renderer = $renderer; $this->alterInfo('local_tasks'); $this->setCacheBackend($cache, 'local_task_plugins:' . $language_manager->getCurrentLanguage()->getId(), array('local_task')); } @@ -314,6 +325,7 @@ '#weight' => $child->getWeight(), '#access' => $access, ); + $this->renderer->addCacheableDependency($build, $access); } } } diff -u b/core/modules/aggregator/src/Tests/AggregatorTestBase.php b/core/modules/aggregator/src/Tests/AggregatorTestBase.php --- b/core/modules/aggregator/src/Tests/AggregatorTestBase.php +++ b/core/modules/aggregator/src/Tests/AggregatorTestBase.php @@ -43,7 +43,7 @@ $this->adminUser = $this->drupalCreateUser(array('access administration pages', 'administer news feeds', 'access news feeds', 'create article content')); $this->drupalLogin($this->adminUser); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** diff -u b/core/modules/block/src/Tests/BlockHiddenRegionTest.php b/core/modules/block/src/Tests/BlockHiddenRegionTest.php --- b/core/modules/block/src/Tests/BlockHiddenRegionTest.php +++ b/core/modules/block/src/Tests/BlockHiddenRegionTest.php @@ -42,7 +42,7 @@ $this->drupalLogin($this->adminUser); $this->drupalPlaceBlock('search_form_block'); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** diff -u b/core/modules/block/src/Tests/BlockTest.php b/core/modules/block/src/Tests/BlockTest.php --- b/core/modules/block/src/Tests/BlockTest.php +++ b/core/modules/block/src/Tests/BlockTest.php @@ -222,7 +222,7 @@ function testThemeName() { // Enable the help block. $this->drupalPlaceBlock('help_block', array('region' => 'help')); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); // Explicitly set the default and admin themes. $theme = 'block_test_specialchars_theme'; \Drupal::service('theme_handler')->install(array($theme)); diff -u b/core/modules/block/src/Tests/NonDefaultBlockAdminTest.php b/core/modules/block/src/Tests/NonDefaultBlockAdminTest.php --- b/core/modules/block/src/Tests/NonDefaultBlockAdminTest.php +++ b/core/modules/block/src/Tests/NonDefaultBlockAdminTest.php @@ -29,7 +29,7 @@ protected function setUp() { parent::setUp(); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** diff -u b/core/modules/block_content/src/Tests/BlockContentTestBase.php b/core/modules/block_content/src/Tests/BlockContentTestBase.php --- b/core/modules/block_content/src/Tests/BlockContentTestBase.php +++ b/core/modules/block_content/src/Tests/BlockContentTestBase.php @@ -60,7 +60,7 @@ } $this->adminUser = $this->drupalCreateUser($this->permissions); - $this->drupalPlaceBlock('system_page_actions_block'); + $this->drupalPlaceBlock('system_local_actions_block'); } /** diff -u b/core/modules/comment/src/Tests/CommentTestBase.php b/core/modules/comment/src/Tests/CommentTestBase.php --- b/core/modules/comment/src/Tests/CommentTestBase.php +++ b/core/modules/comment/src/Tests/CommentTestBase.php @@ -86,7 +86,7 @@ // Create a test node authored by the web user. $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->webUser->id())); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** diff -u b/core/modules/config/src/Tests/ConfigEntityListTest.php b/core/modules/config/src/Tests/ConfigEntityListTest.php --- b/core/modules/config/src/Tests/ConfigEntityListTest.php +++ b/core/modules/config/src/Tests/ConfigEntityListTest.php @@ -33,7 +33,7 @@ // Delete the override config_test entity since it is not required by this // test. \Drupal::entityManager()->getStorage('config_test')->load('override')->delete(); - $this->drupalPlaceBlock('system_page_actions_block'); + $this->drupalPlaceBlock('system_local_actions_block'); } /** diff -u b/core/modules/config_translation/src/Tests/ConfigTranslationListUiTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationListUiTest.php --- b/core/modules/config_translation/src/Tests/ConfigTranslationListUiTest.php +++ b/core/modules/config_translation/src/Tests/ConfigTranslationListUiTest.php @@ -80,7 +80,7 @@ $this->config('locale.settings') ->set('translation.import_enabled', TRUE) ->save(); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** diff -u b/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php --- b/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php +++ b/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php @@ -58,7 +58,7 @@ ConfigurableLanguage::createFromLangcode($langcode)->save(); } $this->localeStorage = $this->container->get('locale.storage'); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** diff -u b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php --- b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php +++ b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php @@ -100,7 +100,7 @@ ConfigurableLanguage::createFromLangcode($langcode)->save(); } $this->localeStorage = $this->container->get('locale.storage'); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** diff -u b/core/modules/contact/src/Tests/ContactSitewideTest.php b/core/modules/contact/src/Tests/ContactSitewideTest.php --- b/core/modules/contact/src/Tests/ContactSitewideTest.php +++ b/core/modules/contact/src/Tests/ContactSitewideTest.php @@ -39,7 +39,7 @@ protected function setUp() { parent::setUp(); $this->drupalPlaceBlock('system_breadcrumb_block'); - $this->drupalPlaceBlock('system_page_actions_block'); + $this->drupalPlaceBlock('system_local_actions_block'); } /** diff -u b/core/modules/field_ui/src/Tests/EntityDisplayModeTest.php b/core/modules/field_ui/src/Tests/EntityDisplayModeTest.php --- b/core/modules/field_ui/src/Tests/EntityDisplayModeTest.php +++ b/core/modules/field_ui/src/Tests/EntityDisplayModeTest.php @@ -29,7 +29,7 @@ protected function setUp() { parent::setUp(); - $this->drupalPlaceBlock('system_page_actions_block'); + $this->drupalPlaceBlock('system_local_actions_block'); } /** diff -u b/core/modules/field_ui/src/Tests/FieldUIRouteTest.php b/core/modules/field_ui/src/Tests/FieldUIRouteTest.php --- b/core/modules/field_ui/src/Tests/FieldUIRouteTest.php +++ b/core/modules/field_ui/src/Tests/FieldUIRouteTest.php @@ -32,7 +32,7 @@ parent::setUp(); $this->drupalLogin($this->rootUser); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** diff -u b/core/modules/field_ui/src/Tests/ManageFieldsTest.php b/core/modules/field_ui/src/Tests/ManageFieldsTest.php --- b/core/modules/field_ui/src/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/src/Tests/ManageFieldsTest.php @@ -68,8 +68,8 @@ parent::setUp(); $this->drupalPlaceBlock('system_breadcrumb_block'); - $this->drupalPlaceBlock('system_page_actions_block'); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_local_actions_block'); + $this->drupalPlaceBlock('system_tabs_block'); // Create a test user. $admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer node fields', 'administer node form display', 'administer node display', 'administer taxonomy', 'administer taxonomy_term fields', 'administer taxonomy_term display', 'administer users', 'administer account settings', 'administer user display', 'bypass node access')); diff -u b/core/modules/filter/src/Tests/FilterAdminTest.php b/core/modules/filter/src/Tests/FilterAdminTest.php --- b/core/modules/filter/src/Tests/FilterAdminTest.php +++ b/core/modules/filter/src/Tests/FilterAdminTest.php @@ -105,7 +105,7 @@ user_role_grant_permissions('authenticated', array($basic_html_format->getPermissionName())); user_role_grant_permissions('anonymous', array($restricted_html_format->getPermissionName())); $this->drupalLogin($this->adminUser); - $this->drupalPlaceBlock('system_page_actions_block'); + $this->drupalPlaceBlock('system_local_actions_block'); } /** diff -u b/core/modules/filter/src/Tests/FilterFormatAccessTest.php b/core/modules/filter/src/Tests/FilterFormatAccessTest.php --- b/core/modules/filter/src/Tests/FilterFormatAccessTest.php +++ b/core/modules/filter/src/Tests/FilterFormatAccessTest.php @@ -114,7 +114,7 @@ $this->secondAllowedFormat->getPermissionName(), $this->disallowedFormat->getPermissionName(), )); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** diff -u b/core/modules/forum/src/Tests/ForumTest.php b/core/modules/forum/src/Tests/ForumTest.php --- b/core/modules/forum/src/Tests/ForumTest.php +++ b/core/modules/forum/src/Tests/ForumTest.php @@ -113,7 +113,7 @@ 'access comments', )); $this->drupalPlaceBlock('help_block', array('region' => 'help')); - $this->drupalPlaceBlock('system_page_actions_block'); + $this->drupalPlaceBlock('system_local_actions_block'); } /** diff -u b/core/modules/language/src/Tests/LanguagePathMonolingualTest.php b/core/modules/language/src/Tests/LanguagePathMonolingualTest.php --- b/core/modules/language/src/Tests/LanguagePathMonolingualTest.php +++ b/core/modules/language/src/Tests/LanguagePathMonolingualTest.php @@ -56,7 +56,7 @@ // Set language detection to URL. $edit = array('language_interface[enabled][language-url]' => TRUE); $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings')); - $this->drupalPlaceBlock('system_page_actions_block'); + $this->drupalPlaceBlock('system_local_actions_block'); } /** diff -u b/core/modules/language/src/Tests/LanguageTourTest.php b/core/modules/language/src/Tests/LanguageTourTest.php --- b/core/modules/language/src/Tests/LanguageTourTest.php +++ b/core/modules/language/src/Tests/LanguageTourTest.php @@ -37,7 +37,7 @@ parent::setUp(); $this->adminUser = $this->drupalCreateUser(array('administer languages', 'access tour')); $this->drupalLogin($this->adminUser); - $this->drupalPlaceBlock('system_page_actions_block'); + $this->drupalPlaceBlock('system_local_actions_block'); } /** diff -u b/core/modules/node/src/Tests/PageEditTest.php b/core/modules/node/src/Tests/PageEditTest.php --- b/core/modules/node/src/Tests/PageEditTest.php +++ b/core/modules/node/src/Tests/PageEditTest.php @@ -28,7 +28,7 @@ $this->webUser = $this->drupalCreateUser(array('edit own page content', 'create page content')); $this->adminUser = $this->drupalCreateUser(array('bypass node access', 'administer nodes')); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** diff -u b/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php b/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php --- b/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php +++ b/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php @@ -58,7 +58,7 @@ // Enable the search block. $this->drupalPlaceBlock('search_form_block'); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** diff -u b/core/modules/search/src/Tests/SearchPageTextTest.php b/core/modules/search/src/Tests/SearchPageTextTest.php --- b/core/modules/search/src/Tests/SearchPageTextTest.php +++ b/core/modules/search/src/Tests/SearchPageTextTest.php @@ -35,7 +35,7 @@ // Create user. $this->searchingUser = $this->drupalCreateUser(array('search content', 'access user profiles', 'use advanced search')); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** diff -u b/core/modules/shortcut/src/Tests/ShortcutSetsTest.php b/core/modules/shortcut/src/Tests/ShortcutSetsTest.php --- b/core/modules/shortcut/src/Tests/ShortcutSetsTest.php +++ b/core/modules/shortcut/src/Tests/ShortcutSetsTest.php @@ -30,7 +30,7 @@ protected function setUp() { parent::setUp(); - $this->drupalPlaceBlock('system_page_actions_block'); + $this->drupalPlaceBlock('system_local_actions_block'); } /** diff -u b/core/modules/simpletest/src/Tests/BrowserTest.php b/core/modules/simpletest/src/Tests/BrowserTest.php --- b/core/modules/simpletest/src/Tests/BrowserTest.php +++ b/core/modules/simpletest/src/Tests/BrowserTest.php @@ -36,7 +36,7 @@ protected function setUp() { parent::setUp(); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** diff -u b/core/modules/system/config/schema/system.schema.yml b/core/modules/system/config/schema/system.schema.yml --- b/core/modules/system/config/schema/system.schema.yml +++ b/core/modules/system/config/schema/system.schema.yml @@ -353,7 +353,7 @@ type: integer label: 'Maximum number of levels' -block.settings.system_page_tabs_block: +block.settings.system_tabs_block: type: block_settings label: 'Tabs block' mapping: reverted: --- b/core/modules/system/src/Plugin/Block/SystemPageActionsBlock.php +++ /dev/null @@ -1,122 +0,0 @@ -localActionManager = $local_action_manager; - $this->routeMatch = $route_match; - } - - /** - * {@inheritdoc} - */ - 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') - ); - } - - /** - * {@inheritdoc} - */ - public function defaultConfiguration() { - return ['label_display' => FALSE]; - } - - /** - * {@inheritdoc} - */ - public function build() { - $build = []; - $links = menu_local_tasks(); - $route_name = $this->routeMatch->getRouteName(); - $action_links = $this->localActionManager->getActionsForRoute($route_name) + $links['actions']; - if (empty($action_links)) { - return []; - } - - $build['action_links'] = $action_links; - - return $build; - } - - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $form = parent::buildConfigurationForm($form, $form_state); - - // The "Page actions" block is never cacheable, due to access checking. - $form['cache']['#disabled'] = TRUE; - $form['cache']['#description'] = $this->t('This block is never cacheable because access checking is needed, it is not configurable.'); - $form['cache']['max_age']['#value'] = 0; - - return $form; - } - - /** - * {@inheritdoc} - */ - public function getCacheMaxAge() { - // @todo Make me cacheable now that https://drupal.org/node/2287071 has landed. - return 0; - } - - - -} reverted: --- b/core/modules/system/src/Plugin/Block/SystemPageTabsBlock.php +++ /dev/null @@ -1,142 +0,0 @@ - FALSE, - 'primary_tasks' => TRUE, - 'secondary_tasks' => TRUE, - ]; - } - - /** - * {@inheritdoc} - */ - public function build() { - $config = $this->configuration; - - $tabs = [ - '#theme' => 'menu_local_tasks', - ]; - if ($config['primary_tasks']) { - $tabs += [ - '#primary' => menu_primary_local_tasks(), - ]; - } - if ($config['secondary_tasks']) { - $tabs += [ - '#secondary' => menu_secondary_local_tasks(), - ]; - } - - if (empty($tabs['#primary']) && empty($tabs['#secondary'])) { - return []; - } - - $build['tabs'] = $tabs; - - return $build; - } - - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $form = parent::buildConfigurationForm($form, $form_state); - - $form['cache']['#disabled'] = TRUE; - $form['cache']['#description'] = $this->t('This block is never cacheable because access checking is needed, it is not configurable.'); - $form['cache']['max_age']['#value'] = 0; - - return $form; - } - - /** - * {@inheritdoc} - */ - public function getCacheMaxAge() { - // @todo Make cacheable now that https://drupal.org/node/2287071 has landed. - return 0; - } - - /** - * {@inheritdoc} - */ - public function getCacheContexts() { - return ['route.name']; - } - - /** - * {@inheritdoc} - */ - public function blockForm($form, FormStateInterface $form_state) { - $config = $this->configuration; - $defaults = $this->defaultConfiguration(); - - $form['levels'] = array( - '#type' => 'details', - '#title' => $this->t('Shown tabs'), - '#description' => $this->t('Select local tasks being shown in the block'), - // Open if not set to defaults. - '#open' => $defaults['primary_tasks'] !== $config['primary_tasks'] || $defaults['secondary_tasks'] !== $config['secondary_tasks'], - ); - $form['levels']['primary_tasks'] = [ - '#type' => 'checkbox', - '#title' => $this->t('Show primary tabs'), - '#default_value' => $config['primary_tasks'], - ]; - $form['levels']['secondary_tasks'] = [ - '#type' => 'checkbox', - '#title' => $this->t('Show secondary tabs'), - '#default_value' => $config['secondary_tasks'], - ]; - - return $form; - } - - /** - * {@inheritdoc} - */ - public function blockSubmit($form, FormStateInterface $form_state) { - $levels = $form_state->getValue('levels'); - $this->configuration['primary_tasks'] = $levels['primary_tasks']; - $this->configuration['secondary_tasks'] = $levels['secondary_tasks']; - } - -} diff -u b/core/modules/system/src/Tests/Menu/LocalActionTest.php b/core/modules/system/src/Tests/Menu/LocalActionTest.php --- b/core/modules/system/src/Tests/Menu/LocalActionTest.php +++ b/core/modules/system/src/Tests/Menu/LocalActionTest.php @@ -30,7 +30,7 @@ protected function setUp() { parent::setUp(); - $this->drupalPlaceBlock('system_page_actions_block'); + $this->drupalPlaceBlock('system_local_actions_block'); } /** diff -u b/core/modules/system/src/Tests/Menu/LocalTasksTest.php b/core/modules/system/src/Tests/Menu/LocalTasksTest.php --- b/core/modules/system/src/Tests/Menu/LocalTasksTest.php +++ b/core/modules/system/src/Tests/Menu/LocalTasksTest.php @@ -30,7 +30,7 @@ protected function setUp() { parent::setUp(); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** diff -u b/core/modules/system/src/Tests/Menu/MenuRouterTest.php b/core/modules/system/src/Tests/Menu/MenuRouterTest.php --- b/core/modules/system/src/Tests/Menu/MenuRouterTest.php +++ b/core/modules/system/src/Tests/Menu/MenuRouterTest.php @@ -43,7 +43,7 @@ parent::setUp(); $this->drupalPlaceBlock('system_menu_block:tools'); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** diff -u b/core/modules/system/src/Tests/Menu/MenuTranslateTest.php b/core/modules/system/src/Tests/Menu/MenuTranslateTest.php --- b/core/modules/system/src/Tests/Menu/MenuTranslateTest.php +++ b/core/modules/system/src/Tests/Menu/MenuTranslateTest.php @@ -31,7 +31,7 @@ protected function setUp() { parent::setUp(); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** diff -u b/core/modules/system/src/Tests/System/DateTimeTest.php b/core/modules/system/src/Tests/System/DateTimeTest.php --- b/core/modules/system/src/Tests/System/DateTimeTest.php +++ b/core/modules/system/src/Tests/System/DateTimeTest.php @@ -29,7 +29,7 @@ // Create admin user and log in admin user. $this->drupalLogin ($this->drupalCreateUser(array('administer site configuration'))); - $this->drupalPlaceBlock('system_page_actions_block'); + $this->drupalPlaceBlock('system_local_actions_block'); } /** diff -u b/core/modules/system/src/Tests/System/ThemeTest.php b/core/modules/system/src/Tests/System/ThemeTest.php --- b/core/modules/system/src/Tests/System/ThemeTest.php +++ b/core/modules/system/src/Tests/System/ThemeTest.php @@ -40,7 +40,7 @@ $this->adminUser = $this->drupalCreateUser(array('access administration pages', 'view the administration theme', 'administer themes', 'bypass node access', 'administer blocks')); $this->drupalLogin($this->adminUser); $this->node = $this->drupalCreateNode(); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** diff -u b/core/modules/system/system.module b/core/modules/system/system.module --- b/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -169,11 +169,11 @@ 'block__system_messages_block' => array( 'base hook' => 'block', ), - 'block__system_page_actions_block' => [ + 'block__system_local_actions_block' => [ 'base hook' => 'block', 'template' => 'block--system-page-actions-block', ], - 'block__system_page_tabs_block' => [ + 'block__system_tabs_block' => [ 'base hook' => 'block', 'template' => 'block--system-page-tabs-block', ], @@ -790,11 +790,11 @@ } break; - case 'system_page_actions_block': + case 'system_local_actions_block': $variables['action_links'] = $variables['content']['action_links']; break; - case 'system_page_tabs_block': + case 'system_tabs_block': $variables['tabs'] = $variables['content']['tabs']; break; diff -u b/core/modules/taxonomy/src/Tests/TermTest.php b/core/modules/taxonomy/src/Tests/TermTest.php --- b/core/modules/taxonomy/src/Tests/TermTest.php +++ b/core/modules/taxonomy/src/Tests/TermTest.php @@ -48,8 +48,8 @@ protected function setUp() { parent::setUp(); - $this->drupalPlaceBlock('system_page_actions_block'); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_local_actions_block'); + $this->drupalPlaceBlock('system_tabs_block'); $this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access'])); $this->vocabulary = $this->createVocabulary(); diff -u b/core/modules/taxonomy/src/Tests/VocabularyUiTest.php b/core/modules/taxonomy/src/Tests/VocabularyUiTest.php --- b/core/modules/taxonomy/src/Tests/VocabularyUiTest.php +++ b/core/modules/taxonomy/src/Tests/VocabularyUiTest.php @@ -29,7 +29,7 @@ parent::setUp(); $this->drupalLogin($this->drupalCreateUser(['administer taxonomy'])); $this->vocabulary = $this->createVocabulary(); - $this->drupalPlaceBlock('system_page_actions_block'); + $this->drupalPlaceBlock('system_local_actions_block'); } /** diff -u b/core/modules/tour/src/Tests/TourTest.php b/core/modules/tour/src/Tests/TourTest.php --- b/core/modules/tour/src/Tests/TourTest.php +++ b/core/modules/tour/src/Tests/TourTest.php @@ -47,7 +47,7 @@ protected function setUp() { parent::setUp(); - $this->drupalPlaceBlock('system_page_actions_block', [ + $this->drupalPlaceBlock('system_local_actions_block', [ 'theme' => 'seven', 'region' => 'actions' ]); diff -u b/core/modules/tracker/src/Tests/TrackerTest.php b/core/modules/tracker/src/Tests/TrackerTest.php --- b/core/modules/tracker/src/Tests/TrackerTest.php +++ b/core/modules/tracker/src/Tests/TrackerTest.php @@ -54,8 +54,8 @@ $this->user = $this->drupalCreateUser($permissions); $this->otherUser = $this->drupalCreateUser($permissions); $this->addDefaultCommentField('node', 'page'); - $this->drupalPlaceBlock('system_page_tabs_block', ['id' => 'page_tabs_block']); - $this->drupalPlaceBlock('system_page_actions_block', ['id' => 'page_actions_block']); + $this->drupalPlaceBlock('system_tabs_block', ['id' => 'page_tabs_block']); + $this->drupalPlaceBlock('system_local_actions_block', ['id' => 'page_actions_block']); } /** diff -u b/core/modules/update/src/Tests/UpdateCoreTest.php b/core/modules/update/src/Tests/UpdateCoreTest.php --- b/core/modules/update/src/Tests/UpdateCoreTest.php +++ b/core/modules/update/src/Tests/UpdateCoreTest.php @@ -28,7 +28,7 @@ parent::setUp(); $admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer modules', 'administer themes')); $this->drupalLogin($admin_user); - $this->drupalPlaceBlock('system_page_actions_block'); + $this->drupalPlaceBlock('system_local_actions_block'); } /** diff -u b/core/modules/user/src/Tests/UserRoleAdminTest.php b/core/modules/user/src/Tests/UserRoleAdminTest.php --- b/core/modules/user/src/Tests/UserRoleAdminTest.php +++ b/core/modules/user/src/Tests/UserRoleAdminTest.php @@ -35,7 +35,7 @@ protected function setUp() { parent::setUp(); $this->adminUser = $this->drupalCreateUser(array('administer permissions', 'administer users')); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** diff -u b/core/modules/views/src/Tests/Plugin/DisplayPageWebTest.php b/core/modules/views/src/Tests/Plugin/DisplayPageWebTest.php --- b/core/modules/views/src/Tests/Plugin/DisplayPageWebTest.php +++ b/core/modules/views/src/Tests/Plugin/DisplayPageWebTest.php @@ -40,7 +40,7 @@ parent::setUp(); $this->enableViewsTestModule(); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** diff -u b/core/modules/views/src/Tests/Wizard/WizardTestBase.php b/core/modules/views/src/Tests/Wizard/WizardTestBase.php --- b/core/modules/views/src/Tests/Wizard/WizardTestBase.php +++ b/core/modules/views/src/Tests/Wizard/WizardTestBase.php @@ -27,7 +27,7 @@ // Create and log in a user with administer views permission. $views_admin = $this->drupalCreateUser(array('administer views', 'administer blocks', 'bypass node access', 'access user profiles', 'view all revisions')); $this->drupalLogin($views_admin); - $this->drupalPlaceBlock('system_page_actions_block'); + $this->drupalPlaceBlock('system_local_actions_block'); } } diff -u b/core/modules/views_ui/src/Tests/SettingsTest.php b/core/modules/views_ui/src/Tests/SettingsTest.php --- b/core/modules/views_ui/src/Tests/SettingsTest.php +++ b/core/modules/views_ui/src/Tests/SettingsTest.php @@ -26,7 +26,7 @@ */ protected function setUp() { parent::setUp(); - $this->drupalPlaceBlock('system_page_tabs_block'); + $this->drupalPlaceBlock('system_tabs_block'); } /** reverted: --- b/core/profiles/minimal/config/install/block.block.stark_page_actions.yml +++ /dev/null @@ -1,18 +0,0 @@ -id: bartik_page_actions -theme: stark -weight: 10 -status: true -langcode: en -region: actions -plugin: system_page_actions_block -settings: - id: system_page_actions_block - label: Page actions - provider: system - label_display: '0' -dependencies: - module: - - system - theme: - - stark -visibility: { } reverted: --- b/core/profiles/minimal/config/install/block.block.stark_page_tabs.yml +++ /dev/null @@ -1,18 +0,0 @@ -id: bartik_page_tabs -theme: stark -weight: 10 -status: true -langcode: en -region: tabs -plugin: system_page_tabs_block -settings: - id: system_page_tabs_block - label: Page tabs - provider: system - label_display: '0' -dependencies: - module: - - system - theme: - - stark -visibility: { } reverted: --- b/core/profiles/standard/config/install/block.block.bartik_page_actions.yml +++ /dev/null @@ -1,18 +0,0 @@ -id: bartik_page_actions -theme: bartik -weight: 10 -status: true -langcode: en -region: actions -plugin: system_page_actions_block -settings: - id: system_page_actions_block - label: Page actions - provider: system - label_display: '0' -dependencies: - module: - - system - theme: - - bartik -visibility: { } reverted: --- b/core/profiles/standard/config/install/block.block.bartik_page_tabs.yml +++ /dev/null @@ -1,18 +0,0 @@ -id: bartik_page_tabs -theme: bartik -weight: 10 -status: true -langcode: en -region: tabs -plugin: system_page_tabs_block -settings: - id: system_page_tabs_block - label: Page tabs - provider: system - label_display: '0' -dependencies: - module: - - system - theme: - - bartik -visibility: { } reverted: --- b/core/profiles/standard/config/install/block.block.seven_page_actions.yml +++ /dev/null @@ -1,18 +0,0 @@ -id: page_actions -theme: seven -weight: 0 -status: true -langcode: en -region: actions -plugin: system_page_actions_block -settings: - id: system_page_actions_block - label: Page actions - provider: system - label_display: '0' -dependencies: - module: - - system - theme: - - seven -visibility: { } diff -u b/core/profiles/standard/config/install/block.block.seven_page_primary_tabs.yml b/core/profiles/standard/config/install/block.block.seven_page_primary_tabs.yml --- b/core/profiles/standard/config/install/block.block.seven_page_primary_tabs.yml +++ b/core/profiles/standard/config/install/block.block.seven_page_primary_tabs.yml @@ -1,12 +1,12 @@ -id: page_primary_tabs +id: seven_primary_tabs theme: seven weight: 0 status: true langcode: en region: primary_tabs -plugin: system_page_tabs_block +plugin: system_tabs_block settings: - id: system_page_tabs_block + id: system_tabs_block label: Primary tabs provider: system label_display: '0' diff -u b/core/profiles/standard/config/install/block.block.seven_page_seconadry_tabs.yml b/core/profiles/standard/config/install/block.block.seven_page_seconadry_tabs.yml --- b/core/profiles/standard/config/install/block.block.seven_page_seconadry_tabs.yml +++ b/core/profiles/standard/config/install/block.block.seven_page_seconadry_tabs.yml @@ -1,12 +1,12 @@ -id: page_secondary_tabs +id: seven_secondary_tabs theme: seven weight: 0 status: true langcode: en region: secondary_tabs -plugin: system_page_tabs_block +plugin: system_tabs_block settings: - id: system_page_tabs_block + id: system_tabs_block label: Secondary tabs provider: system label_display: '0' only in patch2: unchanged: --- a/core/core.services.yml +++ b/core/core.services.yml @@ -498,10 +498,10 @@ services: arguments: ['@menu.link_tree', '@entity.manager', '@string_translation'] plugin.manager.menu.local_action: class: Drupal\Core\Menu\LocalActionManager - arguments: ['@controller_resolver', '@request_stack', '@current_route_match', '@router.route_provider', '@module_handler', '@cache.discovery', '@language_manager', '@access_manager', '@current_user'] + arguments: ['@controller_resolver', '@request_stack', '@current_route_match', '@router.route_provider', '@module_handler', '@cache.discovery', '@language_manager', '@access_manager', '@current_user', '@renderer'] plugin.manager.menu.local_task: class: Drupal\Core\Menu\LocalTaskManager - arguments: ['@controller_resolver', '@request_stack', '@current_route_match', '@router.route_provider', '@module_handler', '@cache.discovery', '@language_manager', '@access_manager', '@current_user'] + arguments: ['@controller_resolver', '@request_stack', '@current_route_match', '@router.route_provider', '@module_handler', '@cache.discovery', '@language_manager', '@access_manager', '@current_user', '@renderer'] plugin.manager.menu.contextual_link: class: Drupal\Core\Menu\ContextualLinkManager arguments: ['@controller_resolver', '@module_handler', '@cache.discovery', '@language_manager', '@access_manager', '@current_user', '@request_stack'] only in patch2: unchanged: --- /dev/null +++ b/core/modules/system/src/Plugin/Block/SystemLocalActionsBlock.php @@ -0,0 +1,127 @@ +localActionManager = $local_action_manager; + $this->routeMatch = $route_match; + } + + /** + * {@inheritdoc} + */ + 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') + ); + } + + /** + * {@inheritdoc} + */ + public function defaultConfiguration() { + return ['label_display' => FALSE]; + } + + /** + * {@inheritdoc} + */ + public function build() { + $build = []; + $links = menu_local_tasks(); + $route_name = $this->routeMatch->getRouteName(); + $action_links = $this->localActionManager->getActionsForRoute($route_name) + $links['actions']; + if (empty($action_links)) { + return []; + } + + $build['action_links'] = $action_links; + + return $build; + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + $form = parent::buildConfigurationForm($form, $form_state); + + // The "Page actions" block is never cacheable because of hooks creating + // local actions doesn't provide cacheability metadata. + $form['cache']['#disabled'] = TRUE; + $form['cache']['#description'] = $this->t('This block is never cacheable because of missing cacheability metadata.'); + $form['cache']['max_age']['#value'] = 0; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function getCacheMaxAge() { + return 0; + } + + /** + * {@inheritdoc} + */ + public function getCacheContexts() { + return ['route.name']; + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/modules/system/src/Plugin/Block/SystemTabsBlock.php @@ -0,0 +1,146 @@ + FALSE, + 'primary_tasks' => TRUE, + 'secondary_tasks' => TRUE, + ]; + } + + /** + * {@inheritdoc} + */ + public function build() { + $config = $this->configuration; + + $tabs = [ + '#theme' => 'menu_local_tasks', + ]; + + // Add only selected levels for the printed output. + if ($config['primary_tasks']) { + $tabs += [ + '#primary' => menu_primary_local_tasks(), + ]; + } + if ($config['secondary_tasks']) { + $tabs += [ + '#secondary' => menu_secondary_local_tasks(), + ]; + } + + if (empty($tabs['#primary']) && empty($tabs['#secondary'])) { + return []; + } + + $build['tabs'] = $tabs; + + return $build; + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + $form = parent::buildConfigurationForm($form, $form_state); + + // The "Page actions" block is never cacheable because of hooks creating + // local tasks doesn't provide cacheability metadata. + $form['cache']['#disabled'] = TRUE; + $form['cache']['#description'] = $this->t('This block is never cacheable because of missing cacheability metadata.'); + $form['cache']['max_age']['#value'] = 0; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function getCacheMaxAge() { + // @todo Make cacheable now that https://drupal.org/node/2287071 has landed. + return 0; + } + + /** + * {@inheritdoc} + */ + public function getCacheContexts() { + return ['route.name']; + } + + /** + * {@inheritdoc} + */ + public function blockForm($form, FormStateInterface $form_state) { + $config = $this->configuration; + $defaults = $this->defaultConfiguration(); + + $form['levels'] = array( + '#type' => 'details', + '#title' => $this->t('Shown tabs'), + '#description' => $this->t('Select local tasks being shown in the block'), + // Open if not set to defaults. + '#open' => $defaults['primary_tasks'] !== $config['primary_tasks'] || $defaults['secondary_tasks'] !== $config['secondary_tasks'], + ); + $form['levels']['primary_tasks'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Show primary tabs'), + '#default_value' => $config['primary_tasks'], + ]; + $form['levels']['secondary_tasks'] = [ + '#type' => 'checkbox', + '#title' => $this->t('Show secondary tabs'), + '#default_value' => $config['secondary_tasks'], + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function blockSubmit($form, FormStateInterface $form_state) { + $levels = $form_state->getValue('levels'); + $this->configuration['primary_tasks'] = $levels['primary_tasks']; + $this->configuration['secondary_tasks'] = $levels['secondary_tasks']; + } + +} only in patch2: unchanged: --- /dev/null +++ b/core/profiles/minimal/config/install/block.block.stark_local_actions.yml @@ -0,0 +1,18 @@ +id: bartik_local_actions +theme: stark +weight: 10 +status: true +langcode: en +region: actions +plugin: system_local_actions_block +settings: + id: system_local_actions_block + label: Local actions + provider: system + label_display: '0' +dependencies: + module: + - system + theme: + - stark +visibility: { } only in patch2: unchanged: --- /dev/null +++ b/core/profiles/minimal/config/install/block.block.stark_tabs.yml @@ -0,0 +1,18 @@ +id: bartik_tabs +theme: stark +weight: 10 +status: true +langcode: en +region: tabs +plugin: system_tabs_block +settings: + id: system_tabs_block + label: Tabs + provider: system + label_display: '0' +dependencies: + module: + - system + theme: + - stark +visibility: { } only in patch2: unchanged: --- /dev/null +++ b/core/profiles/standard/config/install/block.block.bartik_local_actions.yml @@ -0,0 +1,18 @@ +id: bartik_local_actions +theme: bartik +weight: 10 +status: true +langcode: en +region: actions +plugin: system_local_actions_block +settings: + id: system_local_actions_block + label: Local actions + provider: system + label_display: '0' +dependencies: + module: + - system + theme: + - bartik +visibility: { } only in patch2: unchanged: --- /dev/null +++ b/core/profiles/standard/config/install/block.block.bartik_tabs.yml @@ -0,0 +1,18 @@ +id: bartik_tabs +theme: bartik +weight: 10 +status: true +langcode: en +region: tabs +plugin: system_tabs_block +settings: + id: system_tabs_block + label: Tabs + provider: system + label_display: '0' +dependencies: + module: + - system + theme: + - bartik +visibility: { } only in patch2: unchanged: --- /dev/null +++ b/core/profiles/standard/config/install/block.block.seven_local_actions.yml @@ -0,0 +1,18 @@ +id: local_actions +theme: seven +weight: 0 +status: true +langcode: en +region: actions +plugin: system_local_actions_block +settings: + id: system_local_actions_block + label: Local actions + provider: system + label_display: '0' +dependencies: + module: + - system + theme: + - seven +visibility: { }