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.
| Comment | File | Size | Author |
|---|---|---|---|
| #56 | 2752227-56.patch | 8.27 KB | smulvih2 |
| #50 | 2752227-50.patch | 7.2 KB | wengerk |
| #47 | 2752227-47.patch | 7.17 KB | suresh prabhu parkala |
| #45 | page_manager-incorrect-page_title-2752227-45-8.x.4.x.patch | 7.17 KB | milos.kroulik |
| #42 | page_manager-incorrect-page_title-2752227-42-8.x.4.x.patch | 7.8 KB | sylus |
Issue fork page_manager-2752227
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
Comment #2
akalata commentedComment #3
akalata commentedAfter 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.)
Comment #4
hongpong commentedI 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.
Comment #5
hongpong commentedComment #6
leksat commentedFor 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.
Comment #7
leksat commentedOkay, 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)
Comment #9
leksat commentedAdded fallback to page entity label.
Fixed PageManagerRoutesTest.
Comment #10
leksat commentedOkay, 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.
Comment #11
andypostCode 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...
I really find strange to add this method to entity
Basically page title created by display variant plugin
\Drupal\Core\Display\VariantInterfaceLet's get maintainer opinion on that
Comment #12
cyberlex404Do not work for tokens
<title>[node:title] ..more text ...| Site.com</title>Comment #13
leksat commented@cyberlex404, I tested this patch on simplytest.me and tokens in titles work for me there. I tested with [current-user:uid] token.
Comment #14
berdircurrent-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
Comment #15
jlockhartTaking 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.
Comment #17
hongpong commentedIs 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.
Comment #18
j3ll3nlHereby i resumbit a patch which does the job with tokens as a combination of #9 and #19
Comment #19
j3ll3nlI forgot to add the other portions of the #9 patch
Comment #20
a.henry commentedI re-rolled the patch 19 to work with 8.4
Comment #21
dillix commentedComment #24
dillix commented@a.henry I don't know why, but your patch wasn't tested by testbot...
Comment #25
a.henry commentedI 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
Comment #27
ershov.andrey commentedComment #28
ershov.andrey commentedComment #29
cyberlex404I 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)Comment #30
nvexler commentedThis patch applies but doesn't work. Here's the strack trace:
If I revert the patch, I no longer have this error.
Comment #31
nvexler commentedSo it seems like we can fix the issue very similarly to this interdiff: https://www.drupal.org/files/issues/2018-06-13/interdiff-2665328-71-77.txt as per https://www.drupal.org/project/page_manager/issues/2665328#comment-12632427 and https://www.drupal.org/project/page_manager/issues/2665328#comment-12651039
Investigating further.
Comment #32
zseguin commentedUpdated the patch to add similar logic to the patch mentioned in #31.
Comment #33
huzookaComment #34
johnjw59 commentedSmall fix to prevent an error when the page variant context contains only an entity id and not the full entity yet.
Comment #36
szeidler commentedPatch #34 is working fine for me. I'm using tokens for the page title of a page_manager variant.
Comment #37
drclaw commentedWe 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.
Comment #39
charly71 commented+1
Comment #40
anruetherI 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.Comment #41
sylus commentedHere is a patch so this can work with Drupal 9
Comment #42
sylus commentedWhoops bad patch, this one should work.
Comment #43
milos.kroulik commentedThe patch from #42 doesn't work with default configuration of
metatagmodule. It defines page title with tokens like this:[current-page:title] | [site:name]. This leads to following error:Comment #44
berdirit'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.
Comment #45
milos.kroulik commentedThanks. I tried to fix this, the new patch is attached. It seems to be working fine for me.
Comment #46
berdiryes, looks pretty good now, comment here needs to be updated as well.
Comment #47
suresh prabhu parkala commentedUpdated patch as mentioned in #46. Please review.
Comment #48
smulvih2I had a project using patch #42 which worked until our D9 upgrade. Patch #47 works for me on Drupal 9.0.12.
Comment #49
manuel.adanSee #3257213: Route enhacers called multiple times, parameter upcasting / convertion lost if having "Error: Call to a member function getTitle() on string" with this patch.
Comment #50
wengerkRerolled patch
Comment #53
wengerkOpenned 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.
to this
Comment #54
guardiola86 commentedFix in #51 works
Comment #55
joseph.olstadUsing 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**
Comment #56
smulvih2I 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.
Comment #57
dillix commented.del
Comment #59
dillix commentedComment #60
dillix commentedMR in #51 doesn't pass tests on phpunit (next major). So we need fix tests.