Commit d2349620 authored by Dries's avatar Dries

Issue #2068437 by dawehner, pwolanin: Fixed _title does not work on _form.

parent c3dbc269
......@@ -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)));
}
}
......
<?php
/**
* @file
* Contains \Drupal\overlay\Tests\OverlayRenderTest.
*/
namespace Drupal\overlay\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests the rendering of a page in an overlay.
*/
class OverlayRenderTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('test_page_test', 'overlay');
public static function getInfo() {
return array(
'name' => 'Overlay child page rendering',
'description' => 'Tests the rendering of a page in an overlay.',
'group' => 'Overlay',
);
}
/**
* Tests the title of a page in an overlay.
*/
public function testOverlayTitle() {
$account = $this->drupalCreateUser(array('access overlay'));
$this->drupalLogin($account);
$this->drupalGet('admin/test-render-title', array('query' => array('render' => 'overlay')));
$result = $this->xpath('//h1[@id = "overlay-title"]');
$this->assertEqual((string) $result[0], 'Foo');
}
}
......@@ -5,6 +5,7 @@
* Displays the Drupal administration interface in an overlay.
*/
use Drupal\Core\Template\RenderWrapper;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
......@@ -360,7 +361,13 @@ function overlay_preprocess_maintenance_page(&$variables) {
*/
function template_preprocess_overlay(&$variables) {
$variables['tabs'] = menu_primary_local_tasks();
$variables['title'] = drupal_get_title();
if (isset($variables['page']['#title'])) {
$variables['title'] = $variables['page']['#title'];
}
else {
$variables['title'] = new RenderWrapper('drupal_get_title');
}
$variables['disable_overlay'] = overlay_disable_message();
// Add attributes for the overlay container.
......
......@@ -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,20 @@ public function testRenderTitle() {
$this->assertTitle('Foo | Drupal');
$result = $this->xpath('//h1');
$this->assertEqual('Foo', (string) $result[0]);
// Test a controller using _controller instead of _content.
$this->drupalGet('test-render-title-controller');
$this->assertTitle('Foo | Drupal');
$result = $this->xpath('//h1');
$this->assertEqual('Foo', (string) $result[0]);
// Test forms
$this->drupalGet('form-test/object-builder');
$this->assertTitle('Test dynamic title | Drupal');
$result = $this->xpath('//h1');
$this->assertEqual('Test dynamic title', (string) $result[0]);
}
}
......@@ -37,6 +37,9 @@ public function buildForm(array $form, array &$form_state) {
'#type' => 'submit',
'#value' => $this->t('Save'),
);
$form['#title'] = 'Test dynamic title';
return $form;
}
......
......@@ -4,3 +4,18 @@ test_page_render_title:
_content: 'Drupal\test_page_test\Controller\Test::renderTitle'
requirements:
_access: 'TRUE'
admin_test_page_render_title:
pattern: "/admin/test-render-title"
defaults:
_content: 'Drupal\test_page_test\Controller\Test::renderTitle'
requirements:
_access: 'TRUE'
test_page_render_title_controller:
pattern: "/test-render-title-controller"
defaults:
_controller: 'Drupal\test_page_test\Controller\Test::renderTitle'
requirements:
_access: 'TRUE'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment