diff --git a/core/modules/system/src/Plugin/Block/SystemPageActionsBlock.php b/core/modules/system/src/Plugin/Block/SystemPageActionsBlock.php index efe0a4b..53e9b52 100644 --- a/core/modules/system/src/Plugin/Block/SystemPageActionsBlock.php +++ b/core/modules/system/src/Plugin/Block/SystemPageActionsBlock.php @@ -9,8 +9,11 @@ use Drupal\block\BlockBase; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Menu\LocalActionManager; 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. @@ -30,6 +33,27 @@ class SystemPageActionsBlock extends BlockBase implements ContainerFactoryPlugin protected $configFactory; /** + * A local action manger. + * + * @var \Drupal\Core\Menu\LocalActionManager + */ + protected $localActionManager; + + /** + * A route object. + * + * @var \Symfony\Cmf\Component\Routing\RouteObjectInterface + */ + protected $routeObject; + + /** + * A request stack object. + * + * @var \Symfony\Component\HttpFoundation\RequestStack + */ + protected $requestStack; + + /** * Creates a SystemPageActionsBlock instance. * * @param array $configuration @@ -40,10 +64,19 @@ class SystemPageActionsBlock extends BlockBase implements ContainerFactoryPlugin * The plugin implementation definition. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The factory for configuration objects. + * @param \Drupal\Core\Menu\LocalActionManager $localActionManager + * The local action manager. + * @param \Symfony\Cmf\Component\Routing\RouteObjectInterface $routeObject + * The route object. + * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack + * The request stack object. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, LocalActionManager $localActionManager, RouteObjectInterface $routeObject, RequestStack $requestStack) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->configFactory = $config_factory; + $this->localActionManager = $localActionManager; + $this->routeObject = $routeObject; + $this->requestStack = $requestStack; } /** @@ -54,7 +87,10 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('config.factory') + $container->get('config.factory'), + $container->get('local_action_manger'), + $container->get('route_object'), + $container->get('request_stack') ); } @@ -72,7 +108,10 @@ public function defaultConfiguration() { */ public function build() { $build = array(); - $action_links = menu_get_local_actions(); + $links = menu_local_tasks(); + $request = $this->requestStack->getCurrentRequest(); + $route_name = $request->attributes->get(RouteObjectInterface::ROUTE_NAME); + $action_links = $this->localActionManager->getActionsForRoute($route_name) + $links['actions']; $build['action_links'] = array( '#markup' => $action_links, @@ -89,7 +128,7 @@ public function buildConfigurationForm(array $form, array &$form_state) { // The page actions block is never cacheable, because it may be dynamic. $form['cache']['#disabled'] = TRUE; - $form['cache']['#description'] = t('This block is never cacheable, it is not configurable.'); + $form['cache']['#description'] = $this->t('This block is never cacheable, it is not configurable.'); $form['cache']['max_age']['#value'] = 0; return $form; diff --git a/core/modules/system/src/Plugin/Block/SystemPageMessagesBlock.php b/core/modules/system/src/Plugin/Block/SystemPageMessagesBlock.php new file mode 100644 index 0000000..dd7b71d --- /dev/null +++ b/core/modules/system/src/Plugin/Block/SystemPageMessagesBlock.php @@ -0,0 +1,137 @@ +configFactory = $config_factory; + $this->localActionManager = $localActionManager; + $this->routeObject = $routeObject; + $this->requestStack = $requestStack; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('config.factory'), + $container->get('local_action_manger'), + $container->get('route_object'), + $container->get('request_stack') + ); + } + + /** + * {@inheritdoc} + */ + public function defaultConfiguration() { + return array( + 'label_display' => FALSE, + ); + } + + /** + * {@inheritdoc} + */ + public function build() { + return array( + '#theme' => 'status_messages', + ); + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, array &$form_state) { + $form = parent::buildConfigurationForm($form, $form_state); + + // The page messages block is never cacheable, because it may be dynamic. + $form['cache']['#disabled'] = TRUE; + $form['cache']['#description'] = $this->t('This block is never cacheable, it is not configurable.'); + $form['cache']['max_age']['#value'] = 0; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function isCacheable() { + // The page messages block is never cacheable, because it may be dynamic. + return FALSE; + } + +} diff --git a/core/modules/system/src/Plugin/Block/SystemPageTabsBlock.php b/core/modules/system/src/Plugin/Block/SystemPageTabsBlock.php new file mode 100644 index 0000000..275d986 --- /dev/null +++ b/core/modules/system/src/Plugin/Block/SystemPageTabsBlock.php @@ -0,0 +1,106 @@ +configFactory = $config_factory; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('config.factory') + ); + } + + /** + * {@inheritdoc} + */ + public function defaultConfiguration() { + return array( + 'label_display' => FALSE, + ); + } + + /** + * {@inheritdoc} + */ + public function build() { + $build = array(); + $tabs = menu_local_tabs(); + + $build['tabs'] = array( + '#markup' => $tabs, + ); + + return $build; + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, array &$form_state) { + $form = parent::buildConfigurationForm($form, $form_state); + + // The page tabs block is never cacheable, because it may be dynamic. + $form['cache']['#disabled'] = TRUE; + $form['cache']['#description'] = $this->t('This block is never cacheable, it is not configurable.'); + $form['cache']['max_age']['#value'] = 0; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function isCacheable() { + // The page tabs block is never cacheable, because it may be dynamic. + return FALSE; + } + +} diff --git a/core/modules/system/src/Plugin/Block/SystemPageTitleBlock.php b/core/modules/system/src/Plugin/Block/SystemPageTitleBlock.php index 85d57f3..d28edee 100644 --- a/core/modules/system/src/Plugin/Block/SystemPageTitleBlock.php +++ b/core/modules/system/src/Plugin/Block/SystemPageTitleBlock.php @@ -11,6 +11,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Controller\TitleResolverInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RequestStack; @@ -39,6 +40,13 @@ class SystemPageTitleBlock extends BlockBase implements ContainerFactoryPluginIn protected $titleResolver; /** + * A route object. + * + * @var \Symfony\Cmf\Component\Routing\RouteObjectInterface + */ + protected $routeObject; + + /** * A request stack object. * * @var \Symfony\Component\HttpFoundation\RequestStack @@ -58,13 +66,16 @@ class SystemPageTitleBlock extends BlockBase implements ContainerFactoryPluginIn * The factory for configuration objects. * @param \Drupal\Core\Controller\TitleResolverInterface $titleResolver * The title resolver. + * @param \Symfony\Cmf\Component\Routing\RouteObjectInterface $routeObject + * The route object. * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack * The request stack object. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, TitleResolverInterface $titleResolver, RequestStack $requestStack) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, TitleResolverInterface $titleResolver, RouteObjectInterface $routeObject, RequestStack $requestStack) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->configFactory = $config_factory; $this->titleResolver = $titleResolver; + $this->routeObject = $routeObject; $this->requestStack = $requestStack; } @@ -78,6 +89,7 @@ public static function create(ContainerInterface $container, array $configuratio $plugin_definition, $container->get('config.factory'), $container->get('title_resolver'), + $container->get('route_object'), $container->get('request_stack') ); } @@ -98,7 +110,7 @@ public function build() { $build = array(); $title = ''; $request = $this->requestStack->getCurrentRequest(); - if ($route = $request->attributes->get(\Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT)) { + if ($route = $request->attributes->get(routeObjectInterface::ROUTE_OBJECT)) { $title = $this->titleResolver->getTitle($request, $route); } @@ -117,7 +129,7 @@ public function buildConfigurationForm(array $form, array &$form_state) { // The page title block is never cacheable, because it may be dynamic. $form['cache']['#disabled'] = TRUE; - $form['cache']['#description'] = t('This block is never cacheable, it is not configurable.'); + $form['cache']['#description'] = $this->t('This block is never cacheable, it is not configurable.'); $form['cache']['max_age']['#value'] = 0; return $form; diff --git a/core/modules/system/system.module b/core/modules/system/system.module index c21c652..f703fd1 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -174,6 +174,14 @@ function system_theme() { 'base hook' => 'block', 'template' => 'block--system-page-actions-block', ), + 'block__system_page_tabs_block' => array( + 'base hook' => 'block', + 'template' => 'block--system-page-tabs-block', + ), + 'block__system_page_messages_block' => array( + 'base hook' => 'block', + 'template' => 'block--system-page-messages-block', + ), 'system_themes_page' => array( 'variables' => array( 'theme_groups' => array(), @@ -1093,6 +1101,13 @@ function system_preprocess_block(&$variables) { } break; + case 'system_page_tabs_block': + $variables['tabs'] = ''; + if($variables['content']['tabs']['#markup']) { + $variables['tabs'] = $variables['content']['tabs']['#markup']; + } + break; + case 'system_powered_by_block': $variables['attributes']['role'] = 'complementary'; break; diff --git a/core/modules/system/templates/block--system-page-actions-block.html.twig b/core/modules/system/templates/block--system-page-actions-block.html.twig index 9b3335e..a5972dc 100644 --- a/core/modules/system/templates/block--system-page-actions-block.html.twig +++ b/core/modules/system/templates/block--system-page-actions-block.html.twig @@ -5,13 +5,14 @@ * Default theme implementation for page local actions. * * Available variables: - * - action_links: The local actions for the page. + * - action_links: Actions local to the page, such as "Add menu" on the menu + * administration interface. * * @ingroup themeable */ #} {% block content %} - {% if action_links %} - - {% endif %} + {% if action_links %} + + {% endif %} {% endblock %} diff --git a/core/modules/system/templates/block--system-page-messages-block.html.twig b/core/modules/system/templates/block--system-page-messages-block.html.twig new file mode 100644 index 0000000..0d33834 --- /dev/null +++ b/core/modules/system/templates/block--system-page-messages-block.html.twig @@ -0,0 +1,17 @@ +{% extends "@block/block.html.twig" %} +{# +/** + * @file + * Default theme implementation for page messages. + * + * Available variables: + * - messages: Status and error messages. Should be displayed prominently. + * + * @ingroup themeable + */ +#} +{% block content %} + {% if messages %} + {{ messages }} + {% endif %} +{% endblock %} diff --git a/core/modules/system/templates/block--system-page-tabs-block.html.twig b/core/modules/system/templates/block--system-page-tabs-block.html.twig new file mode 100644 index 0000000..780abe7 --- /dev/null +++ b/core/modules/system/templates/block--system-page-tabs-block.html.twig @@ -0,0 +1,16 @@ +{% extends "@block/block.html.twig" %} +{# +/** + * @file + * Default theme implementation for page tabs. + * + * Available variables: + * - tabs: The Tabs linking to any sub-pages beneath the current page (e.g., the + * view and edit tabs when displaying a node). + * + * @ingroup themeable + */ +#} +{% block content %} + {{ tabs }} +{% endblock %} diff --git a/core/modules/system/templates/block--system-page-title-block.html.twig b/core/modules/system/templates/block--system-page-title-block.html.twig index 8ec31ff..aca427c 100644 --- a/core/modules/system/templates/block--system-page-title-block.html.twig +++ b/core/modules/system/templates/block--system-page-title-block.html.twig @@ -15,9 +15,9 @@ */ #} {% block content %} - {{ title_prefix }} - {% if title %} -

{{ title }}

- {% endif %} - {{ title_suffix }} + {{ title_prefix }} + {% if title %} +

{{ title }}

+ {% endif %} + {{ title_suffix }} {% endblock %} diff --git a/core/themes/bartik/templates/block--system-page-actions-block.html.twig b/core/themes/bartik/templates/block--system-page-actions-block.html.twig index 11a9675..b8283b5 100644 --- a/core/themes/bartik/templates/block--system-page-actions-block.html.twig +++ b/core/themes/bartik/templates/block--system-page-actions-block.html.twig @@ -5,15 +5,16 @@ * Bartik's theme implementation for page local actions. * * Available variables: - * - action_links: The local actions for the page. + * - action_links: Actions local to the page, such as "Add menu" on the menu + * administration interface. * * @ingroup themeable */ #} {% block content %} - {% if action_links %} - - {% endif %} + {% if action_links %} + + {% endif %} {% endblock %} diff --git a/core/themes/bartik/templates/block--system-page-messages.html.twig b/core/themes/bartik/templates/block--system-page-messages.html.twig new file mode 100644 index 0000000..0daf784 --- /dev/null +++ b/core/themes/bartik/templates/block--system-page-messages.html.twig @@ -0,0 +1,19 @@ +{% extends "@block/block.html.twig" %} +{# +/** + * @file + * Bartik's theme implementation for page messages. + * + * Available variables: + * - messages: Status and error messages. Should be displayed prominently. + * + * @ingroup themeable + */ +#} +{% block content %} + {% if messages %} +
+ {{ messages }} +
+ {% endif %} +{% endblock %} \ No newline at end of file diff --git a/core/themes/bartik/templates/block--system-page-tabs-block.html.twig b/core/themes/bartik/templates/block--system-page-tabs-block.html.twig new file mode 100644 index 0000000..429ad98 --- /dev/null +++ b/core/themes/bartik/templates/block--system-page-tabs-block.html.twig @@ -0,0 +1,20 @@ +{% extends "@block/block.html.twig" %} +{# +/** + * @file + * Bartik's theme implementation for page tabs. + * + * Available variables: + * - tabs: The Tabs linking to any sub-pages beneath the current page (e.g., the + * view and edit tabs when displaying a node). + * + * @ingroup themeable + */ +#} +{% block content %} + {% if tabs %} + + {% endif %} +{% endblock %} diff --git a/core/themes/bartik/templates/block--system-page-title-block.html.twig b/core/themes/bartik/templates/block--system-page-title-block.html.twig index 1b7e66f..4bd27f1 100644 --- a/core/themes/bartik/templates/block--system-page-title-block.html.twig +++ b/core/themes/bartik/templates/block--system-page-title-block.html.twig @@ -15,11 +15,11 @@ */ #} {% block content %} - {{ title_prefix }} - {% if title %} -

- {{ title }} -

- {% endif %} - {{ title_suffix }} + {{ title_prefix }} + {% if title %} +

+ {{ title }} +

+ {% endif %} + {{ title_suffix }} {% endblock %}