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

8.0.x
Dries 2013-09-06 13:32:52 -04:00
parent c3dbc26969
commit d234962047
6 changed files with 97 additions and 2 deletions

View File

@ -71,6 +71,12 @@ class ViewSubscriber implements EventSubscriberInterface {
'#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 @@ class ViewSubscriber implements EventSubscriberInterface {
'#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)));
}
}

View File

@ -0,0 +1,44 @@
<?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');
}
}

View File

@ -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.

View File

@ -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 @@ class PageTitleTest extends WebTestBase {
$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]);
}
}

View File

@ -37,6 +37,9 @@ class FormTestObject extends FormBase {
'#type' => 'submit',
'#value' => $this->t('Save'),
);
$form['#title'] = 'Test dynamic title';
return $form;
}

View File

@ -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'