diff --git a/core/lib/Drupal/Core/Entity/EntityListController.php b/core/lib/Drupal/Core/Entity/EntityListController.php index 7312e3f..71c9c24 100644 --- a/core/lib/Drupal/Core/Entity/EntityListController.php +++ b/core/lib/Drupal/Core/Entity/EntityListController.php @@ -202,6 +202,7 @@ public function render() { $build = array( '#theme' => 'table', '#header' => $this->buildHeader(), + '#title' => $this->getTitle(), '#rows' => array(), '#empty' => t('There is no @label yet.', array('@label' => $this->entityInfo['label'])), ); @@ -249,4 +250,15 @@ public function setTranslationManager(TranslationInterface $translation_manager) return $this; } + /** + * Returns the title of the form. + * + * @return string + * A string title of the page. + * + */ + protected function getTitle() { + return; + } + } diff --git a/core/modules/block/custom_block/custom_block.routing.yml b/core/modules/block/custom_block/custom_block.routing.yml index 3d16354..bd2fc96 100644 --- a/core/modules/block/custom_block/custom_block.routing.yml +++ b/core/modules/block/custom_block/custom_block.routing.yml @@ -9,6 +9,7 @@ custom_block.add_page: path: '/block/add' defaults: _content: 'Drupal\custom_block\Controller\CustomBlockController::add' + _title: 'Add custom block' requirements: _permission: 'administer blocks' @@ -16,6 +17,7 @@ custom_block.add_form: path: block/add/{custom_block_type} defaults: _content: 'Drupal\custom_block\Controller\CustomBlockController::addForm' + _title_callback: 'Drupal\custom_block\Controller\CustomBlockController::getFormTitle' requirements: _permission: 'administer blocks' diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Controller/CustomBlockController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Controller/CustomBlockController.php index 1bcfa20..81a66e9 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Controller/CustomBlockController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Controller/CustomBlockController.php @@ -8,13 +8,14 @@ namespace Drupal\custom_block\Controller; use Drupal\Component\Plugin\PluginManagerInterface; +use Drupal\Core\Controller\ControllerBase; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\custom_block\CustomBlockTypeInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; -class CustomBlockController implements ContainerInjectionInterface { +class CustomBlockController extends ControllerBase implements ContainerInjectionInterface { /** * The entity manager. @@ -98,10 +99,6 @@ public function add(Request $request) { * A form array as expected by drupal_render(). */ public function addForm(CustomBlockTypeInterface $custom_block_type, Request $request) { - // @todo Remove this when https://drupal.org/node/1981644 is in. - drupal_set_title(t('Add %type custom block', array( - '%type' => $custom_block_type->label() - )), PASS_THROUGH); $block = $this->customBlockStorage->create(array( 'type' => $custom_block_type->id() )); @@ -114,4 +111,17 @@ public function addForm(CustomBlockTypeInterface $custom_block_type, Request $re return $this->entityManager->getForm($block); } + /** + * Provides the page title for this controller. + * + * @param \Drupal\custom_block\CustomBlockTypeInterface $custom_block_type + * The custom block type being added. + * + * @return string + * The page title. + */ + public function getFormTitle(CustomBlockTypeInterface $custom_block_type) { + return $this->t('Add %type custom block', array('%type' => $custom_block_type->label())); + } + } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php index efa4380..ea57b63 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeListController.php @@ -51,9 +51,14 @@ public function buildRow(EntityInterface $entity) { * {@inheritdoc} */ public function render() { - // @todo Remove this once https://drupal.org/node/2032535 is in. - drupal_set_title(t('Custom block types')); return parent::render(); } + /** + * {@inheritdoc} + */ + protected function getTitle() { + return $this->t('Custom block types'); + } + }