diff --git a/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php index fa4be98..ae1d083 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php @@ -71,6 +71,12 @@ public function onView(GetResponseForControllerResultEvent $event) { '#markup' => $page_result, ); } + + // If no title was returned fall back to one defined in the route. + if (!isset($page_result['#title']) && $request->attributes->has('_title')) { + $page_result['#title'] = $request->attributes->get('_title'); + } + $event->setResponse(new Response(drupal_render_page($page_result))); } else { @@ -83,6 +89,12 @@ public function onView(GetResponseForControllerResultEvent $event) { '#markup' => $page_result, ); } + + // If no title was returned fall back to one defined in the route. + if (!isset($page_result['#title']) && $request->attributes->has('_title')) { + $page_result['#title'] = $request->attributes->get('_title'); + } + $event->setResponse(new Response(drupal_render($page_result))); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/System/PageTitleTest.php b/core/modules/system/lib/Drupal/system/Tests/System/PageTitleTest.php index 942fa9e..c7c90e5 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/PageTitleTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/PageTitleTest.php @@ -19,7 +19,7 @@ class PageTitleTest extends WebTestBase { * * @var array */ - public static $modules = array('node', 'test_page_test'); + public static $modules = array('node', 'test_page_test', 'form_test'); protected $content_user; protected $saved_title; @@ -136,6 +136,12 @@ public function testRenderTitle() { $this->assertTitle('Foo | Drupal'); $result = $this->xpath('//h1'); $this->assertEqual('Foo', (string) $result[0]); + + $this->drupalGet('form-test/object-builder'); + + $this->assertTitle('Test title | Drupal'); + $result = $this->xpath('//h1'); + $this->assertEqual('Test title', (string) $result[0]); } } diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php index 1ec5f71..fc73e96 100644 --- a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestObject.php @@ -37,6 +37,9 @@ public function buildForm(array $form, array &$form_state) { '#type' => 'submit', '#value' => $this->t('Save'), ); + + $form['#title'] = 'Test title'; + return $form; }