Unverified Commit 53b1df59 authored by git's avatar git Committed by jibran

Issue #2722807 by Bambell, jibran: Allow setting page title based on form title

parent 69378a35
......@@ -42,4 +42,30 @@ class ContactStorageController extends ContactController {
return $view_builder->view($contact_form, 'full', $contact_form->language());
}
/**
* Route title callback.
*
* @param \Drupal\contact\ContactFormInterface $contact_form
* The contact form.
*
* @return string
* The title of the contact form.
*/
public function contactFormTitle(ContactFormInterface $contact_form) {
return $contact_form->label();
}
/**
* Edit route title callback.
*
* @param \Drupal\contact\ContactFormInterface $contact_form
* The contact form.
*
* @return string
* The title of the contact form.
*/
public function contactEditFormTitle(ContactFormInterface $contact_form) {
return $this->t('Edit @label', ['@label' => $contact_form->label()]);
}
}
......@@ -18,7 +18,12 @@ class RouteSubscriber extends RouteSubscriberBase {
// Change the contact_form controller.
if ($route = $collection->get('entity.contact_form.canonical')) {
$route->setDefault('_controller', ContactStorageController::class . '::contactSitePage');
$route->setDefault('_title_callback', ContactStorageController::class . '::contactFormTitle');
}
if ($route = $collection->get('entity.contact_form.edit_form')) {
$route->setDefault('_title_callback', ContactStorageController::class . '::contactEditFormTitle');
}
}
}
......@@ -120,6 +120,16 @@ class ContactStorageTest extends ContactStorageTestBase {
"Subject",
];
// Check that the page title is correct.
$this->drupalGet('contact/test_id');
$this->assertTrue(!empty($this->cssSelect('h1:contains(test_label)')));
$this->assertTitle('test_label | Drupal');
// Check that the configuration edit page title is correct.
$this->drupalGet('admin/structure/contact/manage/test_id');
$this->assertTrue(!empty($this->cssSelect('h1:contains(test_label)')));
$this->assertTitle('Edit test_label | Drupal');
// Check that name, subject and mail are configurable on display.
$this->drupalGet('admin/structure/contact/manage/test_id/display');
foreach ($display_fields as $label) {
......
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