On a page manager blocks display page, the variant's configured page title is displaying correctly in the page title block (<h1>), but in the <title> is using the Label set for the Page overall, instead of the defined variant title.

This wouldn't be too bad except I can't find a way to change the Page's label within the UI.

I've tracked the issue down to the _title callback in the dynamic route creation of PageMangerRoutes.php, (currently on) line 99:

'_title' => $entity->label(),

Original report by divined:

$request = \Drupal::request();
$route_object = \Drupal::routeMatch()->getRouteObject();
$page_title = \Drupal::service('title_resolver')->getTitle($request, $route_object);

Return page manager name instead of Page title.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

divined created an issue. See original summary.

akalata’s picture

Title: title_resolver service not work. » Incorrect page_title in browser toolbar
Version: 8.x-1.0-alpha23 » 8.x-1.x-dev
Issue summary: View changes
akalata’s picture

StatusFileSize
new1.51 KB

After some poking, I think I got close to the changes that were needed?

(Intentionally not changing status since there isn't something complete to review.)

hongpong’s picture

Priority: Normal » Major

I am trying to use a page manager for my front page and applied your patch to the dev version available today and it did not improve the problem. The variant page title is still not picked up. Going to remake the page instead.

I'm bumping this to major because it doesn't seem to be possible to control the page title on the front page from the UI.

hongpong’s picture

Title: Incorrect page_title in browser toolbar » Incorrect page_title title in browser toolbar
Related issues: +#2665328: Fix Variants take entity label, not the variant title
leksat’s picture

For me this happens because the metatag module is installed.

Just tested at simplytest.me:
- installed page_manager, created new page => the html <title> is created from variant title
- installed metatag => the html <title> is created from page label

Will look into this deeper.

leksat’s picture

Status: Active » Needs review
StatusFileSize
new2.96 KB
new3.21 KB

Okay, so this happens because page route has title set from the page entity label.
(And this was in the issue description from the moment I started work on that. I have to read more :D)

Status: Needs review » Needs work

The last submitted patch, 7: 2752227-7.patch, failed testing.

leksat’s picture

Status: Needs work » Needs review
StatusFileSize
new5.8 KB
new3.24 KB

Added fallback to page entity label.
Fixed PageManagerRoutesTest.

leksat’s picture

Okay, tests are green, yet I'm not sure about the page entity label fallback. Tests expect it, so I guess it was planned like this from the beginning. But, in my opinion, page entity label is part of the admin interface and should not ever be shown to website visitors.

andypost’s picture

Code looks good but I think it's wrong to have this method in entity, this is a feature of variant to have title or not (there's response code variant)

Otoh title may stored in variant with rules to display it but I see no way to make cheap call for variant plugin with title callback

But this makes sense to have title_callback somehow to render breadcrumbs...

+++ b/src/PageVariantInterface.php
@@ -181,4 +181,11 @@ interface PageVariantInterface extends ConfigEntityInterface, EntityWithPluginCo
+  public function getPageTitle();

I really find strange to add this method to entity
Basically page title created by display variant plugin \Drupal\Core\Display\VariantInterface

Let's get maintainer opinion on that

cyberlex404’s picture

Status: Needs review » Needs work

Do not work for tokens
<title>[node:title] ..more text ...| Site.com</title>

leksat’s picture

Status: Needs work » Needs review

@cyberlex404, I tested this patch on simplytest.me and tokens in titles work for me there. I tested with [current-user:uid] token.

berdir’s picture

current-user doesn't depend on site-specific content. [node:title] for a custom page that receives a node as argument is a very different scenario, you get into problems similar to what I described in #2837833: PageManager pages access broken

jlockhart’s picture

Taking a crack at this. Our use case is ShareThis. The module pulls the node title for sharing but ends up getting the variant title.
I've rerolled this patch and it solved our issue.

I updated the patch for the latest dev. Then I added handling that gets the page entity and passes the variant title setting through Drupal::token();
At the moment I have only tested this with a Node, I'll test with taxonomy terms and users soon.

Status: Needs review » Needs work
hongpong’s picture

Is there a quick way to do a one-off in the theme file to change a page title on a single page_manager page? I can't seem to get it away from the administrative name.

j3ll3nl’s picture

StatusFileSize
new1.29 KB

Hereby i resumbit a patch which does the job with tokens as a combination of #9 and #19

j3ll3nl’s picture

StatusFileSize
new6.29 KB

I forgot to add the other portions of the #9 patch

a.henry’s picture

I re-rolled the patch 19 to work with 8.4

dillix’s picture

Version: 8.x-1.x-dev » 8.x-4.x-dev
Status: Needs work » Needs review

The last submitted patch, 18: 2752227-17.patch, failed testing.

The last submitted patch, 19: 2752227-19.patch, failed testing.

dillix’s picture

@a.henry I don't know why, but your patch wasn't tested by testbot...

a.henry’s picture

I didn't select the test when uploading the patch, as I could only see version 8.x.1.x-dev in the 'Test with ' select list.
Patch re uploaded with tests but I still cannot select 8.x.4.x-dev to test with

Status: Needs review » Needs work

The last submitted patch, 25: page_manager-incorrect-page_title-2752227-25-8.x.4.x.patch, failed testing.

ershov.andrey’s picture

Assigned: Unassigned » ershov.andrey
ershov.andrey’s picture

Assigned: ershov.andrey » Unassigned
cyberlex404’s picture

I fixed the problem with the title on the "page manager" page using my own RouteSubscriber class
See details https://gist.github.com/cyberlex404/98701fbfcb74600568642123983527aa
Use $events[RoutingEvents::ALTER] = ['onAlterRoutes', -170]; (-160 in Drupal\page_manager\Routing\PageManagerRoutes)

nvexler’s picture

This patch applies but doesn't work. Here's the strack trace:

The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\page_manager\Controller\PageManagerController::pageTitle() must implement interface Drupal\page_manager\PageVariantInterface, string given in Drupal\page_manager\Controller\PageManagerController->pageTitle() (line 21 of modules/contrib/page_manager/src/Controller/PageManagerController.php).
Drupal\page_manager\Controller\PageManagerController->pageTitle('applications_list-panels_variant-0')
call_user_func_array(Array, Array) (Line: 47)
Drupal\Core\Controller\TitleResolver->getTitle(Object, Object) (Line: 50)
Drupal\bootstrap\Plugin\Preprocess\Breadcrumb->preprocessVariables(Object) (Line: 57)
Drupal\bootstrap\Plugin\Preprocess\PreprocessBase->preprocess(Array, 'breadcrumb', Array) (Line: 31)
Drupal\wxt_bootstrap\Plugin\Preprocess\Breadcrumb->preprocess(Array, 'breadcrumb', Array) (Line: 1138)
Drupal\bootstrap\Bootstrap::preprocess(Array, 'breadcrumb', Array) (Line: 117)
bootstrap_preprocess(Array, 'breadcrumb', Array) (Line: 293)
Drupal\Core\Theme\ThemeManager->render('breadcrumb', Array) (Line: 437)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 490)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 51)
__TwigTemplate_4a7fbeb1e4f93f2cad2a8cb9a66b6479bdd029f7ee6edfb0aeda72db030b3b28->block_content(Array, Array) (Line: 215)
Twig_Template->displayBlock('content', Array, Array) (Line: 44)
__TwigTemplate_4a7fbeb1e4f93f2cad2a8cb9a66b6479bdd029f7ee6edfb0aeda72db030b3b28->doDisplay(Array, Array) (Line: 432)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 403)
Twig_Template->display(Array) (Line: 411)
Twig_Template->render(Array) (Line: 64)
twig_render_template('themes/custom/wxt_bootstrap/templates/block/block--system-breadcrumb-block.html.twig', Array) (Line: 390)
Drupal\Core\Theme\ThemeManager->render('block', Array) (Line: 437)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 450)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 490)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 230)
__TwigTemplate_5fc06def5f1c923a5058d329e8ee8bea9ad57daa967fd1fb58e37621bde4a4a9->block_navbar(Array, Array) (Line: 215)
Twig_Template->displayBlock('navbar', Array, Array) (Line: 62)
__TwigTemplate_5fc06def5f1c923a5058d329e8ee8bea9ad57daa967fd1fb58e37621bde4a4a9->doDisplay(Array, Array) (Line: 432)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 403)
Twig_Template->display(Array) (Line: 411)
Twig_Template->render(Array) (Line: 64)
twig_render_template('themes/custom/wxt_bootstrap/templates/page/page--gcweb.html.twig', Array) (Line: 390)
Drupal\Core\Theme\ThemeManager->render('page', Array) (Line: 437)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 490)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 116)
__TwigTemplate_ff415bbc13266bc8c8e07886b1c4987ae64a1f915adbe583e39517232d6f13e0->doDisplay(Array, Array) (Line: 432)
Twig_Template->displayWithErrorHandling(Array, Array) (Line: 403)
Twig_Template->display(Array) (Line: 411)
Twig_Template->render(Array) (Line: 64)
twig_render_template('themes/custom/wxt_bootstrap/templates/system/html.html.twig', Array) (Line: 390)
Drupal\Core\Theme\ThemeManager->render('html', Array) (Line: 437)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array) (Line: 147)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 148)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 664)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

If I revert the patch, I no longer have this error.

zseguin’s picture

Updated the patch to add similar logic to the patch mentioned in #31.

huzooka’s picture

Status: Needs work » Needs review
johnjw59’s picture

Small fix to prevent an error when the page variant context contains only an entity id and not the full entity yet.

Status: Needs review » Needs work

The last submitted patch, 34: page_manager-incorrect-page_title-2752227-34-8.x.4.x.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

szeidler’s picture

Status: Needs work » Needs review

Patch #34 is working fine for me. I'm using tokens for the page title of a page_manager variant.

drclaw’s picture

We may as well try and load any non-object contexts. This was an issue for me specifically with the [current-page:title] token on "node_view"
page variant pages being used in metatags. I dug in as far as to figure out that somehow the current request object was getting the 'node' attribute reset to it's string value rather than the fully loaded node. Not 100% sure where it's happening but it's likely the same thing that's causing the "Argument 1 passed to Drupal\page_manager\Controller\PageManagerController::pageTitle() must implement interface Drupal\page_manager\PageVariantInterface, string given" error described in comment #30.

Patch and interdiff attached to try and load non-object contexts.

Status: Needs review » Needs work

The last submitted patch, 37: page_manager-incorrect-page_title-2752227-37-8.x.4.x.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

charly71’s picture

+1

anruether’s picture

I can't find the title field in the UI with the patch applied, #34/#37. I use 4.x-beta6

But without a patch from this issue (tried #34/#37) I can't use a term token in the page manager label. The token will just be printed out without being replaced. With the patch, it works correctly.

EDIT: After deployment, this shows [term:name] as page title and not the resoved token, I did not investigate further.

langcode: en
status: true
dependencies: {  }
id: h4c_taxonomy_term_page
label: '[term:name]'
description: ''
use_admin_theme: false
path: '/taxonomy/term/{taxonomy_term}'
access_logic: and
access_conditions: {  }
parameters: {  }
sylus’s picture

Here is a patch so this can work with Drupal 9

sylus’s picture

Whoops bad patch, this one should work.

milos.kroulik’s picture

The patch from #42 doesn't work with default configuration of metatag module. It defines page title with tokens like this: [current-page:title] | [site:name]. This leads to following error:

Error: Call to undefined method Drupal\Core\Entity\EntityTypeManager::loadEntityByConfigTarget() in Drupal\page_manager\Controller\PageManagerController->pageTitle() (line 47 of modules/contrib/page_manager/src/Controller/PageManagerController.php). 
berdir’s picture

+++ b/src/Controller/PageManagerController.php
@@ -0,0 +1,68 @@
+   */
+  public function pageTitle($page_manager_page_variant) {
+    if (is_string($page_manager_page_variant)) {
+      $page_manager_page_variant = $this->entityManager->loadEntityByConfigTarget('page_variant', $page_manager_page_variant);
+    }
+

it's not related to metatag configuration, the problem is that this patch is not Drupal 9 compatible, this method is on entity repository, not entity type manager. So injected service and property name needs to be updated.

milos.kroulik’s picture

Thanks. I tried to fix this, the new patch is attached. It seems to be working fine for me.

berdir’s picture

+++ b/src/Controller/PageManagerController.php
@@ -0,0 +1,69 @@
+class PageManagerController extends ControllerBase {
+  /**
+   * The entity manager service.

yes, looks pretty good now, comment here needs to be updated as well.

suresh prabhu parkala’s picture

Status: Needs work » Needs review
StatusFileSize
new7.17 KB

Updated patch as mentioned in #46. Please review.

smulvih2’s picture

I had a project using patch #42 which worked until our D9 upgrade. Patch #47 works for me on Drupal 9.0.12.

manuel.adan’s picture

wengerk’s picture

StatusFileSize
new7.2 KB

Rerolled patch

wengerk changed the visibility of the branch 2752227-incorrect-pagetitle-title to hidden.

wengerk’s picture

Openned an issue fork to run tests againts patch. I found some mistake on the rerolled patch in #50 and fix thoses issues on the Fork.
Seems to works now. I just rerolled the patch and change this code.

  public function pageTitle($page_manager_page_variant) {
    if (is_string($page_manager_page_variant)) {
        $page_manager_page_variant = $this->entityRepository->loadEntityByConfigTarget('page_variant', $page_manager_page_variant);
    }

to this

  public function pageTitle(Request $request) {
    $attributes = $request->attributes->all();
    if (!isset($attributes['_page_manager_page_variant'])) {
      return '';
    }

    if (is_string($attributes['_page_manager_page_variant'])) {
      $page_manager_page_variant = $this->entityRepository->loadEntityByConfigTarget('page_variant', $attributes['_page_manager_page_variant']);
    } elseif ($attributes['_page_manager_page_variant'] instanceof PageVariantInterface) {
      $page_manager_page_variant = $attributes['_page_manager_page_variant'];
    } else {
      return '';
    }
guardiola86’s picture

Fix in #51 works

joseph.olstad’s picture

Using page_manager with Drupal 11 I had to make this change otherwise I could not log into my site:

**EDIT**

Use MR #51 or better

**END EDIT**

smulvih2’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new8.27 KB

I was using patch #50 and this was causing an error after logging into my site. Using the latest MR from #51 fixed the issue for me, and now I can login to my site without error. Posting latest patch here so I can use it in my project.

dillix’s picture

Status: Reviewed & tested by the community » Needs work

.del

dillix changed the visibility of the branch 8.x-4.x to hidden.

dillix’s picture

Status: Needs work » Reviewed & tested by the community
dillix’s picture

Status: Reviewed & tested by the community » Needs work

MR in #51 doesn't pass tests on phpunit (next major). So we need fix tests.