diff --git a/core/modules/system/src/Plugin/Block/SystemTitleBlock.php b/core/modules/system/src/Plugin/Block/SystemTitleBlock.php index 296f508..2a47f5b 100644 --- a/core/modules/system/src/Plugin/Block/SystemTitleBlock.php +++ b/core/modules/system/src/Plugin/Block/SystemTitleBlock.php @@ -9,9 +9,10 @@ use Drupal\block\BlockBase; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Controller\TitleResolverInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\Component\Utility\Xss; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\RequestStack; /** * Provides a block to display the page title. @@ -31,6 +32,20 @@ class SystemTitleBlock extends BlockBase implements ContainerFactoryPluginInterf protected $configFactory; /** + * The title resolver. + * + * @var \Drupal\Core\Controller\TitleResolverInterface + */ + protected $titleResolver; + + /** + * A request stack object. + * + * @var \Symfony\Component\HttpFoundation\RequestStack + */ + protected $requestStack; + + /** * Creates a SystemBrandingBlock instance. * * @param array $configuration @@ -41,10 +56,16 @@ class SystemTitleBlock extends BlockBase implements ContainerFactoryPluginInterf * The plugin implementation definition. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The factory for configuration objects. + * @param \Drupal\Core\Controller\TitleResolverInterface $titleResolver + * The title resolver. + * @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, TitleResolverInterface $titleResolver, RequestStack $requestStack) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->configFactory = $config_factory; + $this->titleResolver = $titleResolver; + $this->requestStack = $requestStack; } /** @@ -55,22 +76,42 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('config.factory') + $container->get('config.factory'), + $container->get('title_resolver'), + $container->get('request_stack') ); } /** * {@inheritdoc} */ - public function build() { + public function defaultConfiguration() { return array( - \Drupal::config('system.site')->get('name') + 'label_display' => FALSE, ); } /** * {@inheritdoc} */ + public function build() { + $build = array(); + $title = ''; + $request = $this->requestStack->getCurrentRequest(); + if ($route = $request->attributes->get(\Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT)) { + $title = $this->titleResolver->getTitle($request, $route); + } + + $build['title'] = array( + '#markup' => $title, + ); + + return $build; + } + + /** + * {@inheritdoc} + */ public function buildConfigurationForm(array $form, array &$form_state) { $form = parent::buildConfigurationForm($form, $form_state); diff --git a/core/modules/system/system.module b/core/modules/system/system.module index a7b418a..e8c733f 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1076,6 +1076,13 @@ function system_preprocess_block(&$variables) { } break; + case 'system_title_block': + $variables['title'] = ''; + if($variables['content']['title']['#markup']) { + $variables['title'] = $variables['content']['title']['#markup']; + } + break; + case 'system_powered_by_block': $variables['attributes']['role'] = 'complementary'; break;