Problem/Motivation
When viewing a Draft revision of a content entity on its "Latest version" tab (eg node/X/latest), the page incorrectly displays the latest Published revision as the page title, as used by the Page Title block.
Steps to reproduce
- Install core "standard" profile
- Install html_title module 8.x-1.3
- Enable HTML Title and Content Moderation modules
- Configure the Editorial workflow to apply to the Article content type (
admin/config/workflow/workflows/manage/editorial) - Create an Article node (
node/add/article), give it the title Original Title, enter Original body in the body field, and save a Published revision. - Edit the same node, and change the title to Draft Title, change the body to Draft body, then save a new Draft revision.
- Observe that you are on the "Latest version" tab (
node/1/latest), the body of the node correctly displays Draft body, but the title displayed is Original title, whereas we should see Draft Title.
Proposed resolution
I tracked this bug down to the way the node is loaded in HTML Title's hook_preprocess_page_title() implementation, and have a working fix I'll share shortly. The crux seems to be the difference between calling
RouteMatch::getRawParameter('node')
to get a `nid` to subsequently load the node, and calling
RouteMatch::getParameter('node')
, which returns an already-loaded Node object of the correct draft revision, and thus we get the appropriate title. Presumably we would need to explicitly check for and request the appropriate revision when loading the node from its nid, but fortunately the getParameter() handles this for us.
Remaining tasks
- Create an issue fork and submit a Merge Request
- Write test coverage for this fix
- Review and validate the fix
- Commit and merge :)
User interface changes
The title of draft nodes on the Latest version tab will display the correct title.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | interdiff_5-7.txt | 634 bytes | narendra.rajwar27 |
| #7 | 3241474-7.patch | 2.6 KB | narendra.rajwar27 |
| #5 | html_title-fix-revision-revert-3241474-5.patch | 2.52 KB | dowdkie |
Issue fork html_title-3241474
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 #3
spidermanComment #4
spidermanI've taken a crack at writing a test to cover this scenario, based off the Content Moderation module's tests, and the simple steps to reproduce. Unfortunately both efforts have failed, so hopefully somebody with more knowhow can fill this in. I've also pushed the actual fix on the MR, to demonstrate working behaviour.
Comment #5
dowdkie commentedWhen using this patch I've narrowed down the issue to this patch, I've had to reroll the patch to check and make sure the node parameter object is of instance type node.
Comment #7
narendra.rajwar27Trying to fix test failures.
Comment #10
richardbporter commentedThe patch worked for us. I updated the MR to fix the test failures and add another assertions for the original title.
Comment #11
richardbporter commentedComment #12
richardbporter commentedThe test failures are seemingly unrelated as they're failing on another issue as well. The
HtmlTitleDraftTestis passing based on the job logs: https://git.drupalcode.org/issue/html_title-3241474/-/jobs/581937. Marking as RTBC.Comment #13
richardbporter commentedComment #15
generalredneckFirst I made some changes to the test as it appears they were written before the modules parameter became "protected".
Second, I added some HTML to the tests to ensure that html_title continues to function as expected there as well.
Lastly, The recent test failures are do to changes in Drupal 10.2.*. This test works solo in 10.2.*. Running the tests (including this one solo) against 10.1.8 work fine, so I'm going to call this one good to go and will work to find the challenges in 10.2. I suspect it's part of #3413257: Only first element tag in configuration form is rendered in title on Drupal 10.2.
Comment #17
generalredneckMerged this in.