Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In D7.
I have created a node with custom page title 'my page title'.
I then re-edit the node and want the page title field to be empty (so as to use the site default page title set in admin/config/search/page-title)
However on saving, the old page title 'my page title' shows up.
Looking into the code:
function page_title_node_insert($node) {
if (user_access('set page title') && isset($node->page_title) && drupal_strlen(trim($node->page_title)) > 0) {
db_insert('page_title')->fields(array('type' => 'node', 'id' => $node->nid, 'page_title' => $node->page_title))->execute();
}
}
The page_title is saved only if strlen > 0. Why? Can we not erase previous page title to go back to defaults?
Comment | File | Size | Author |
---|---|---|---|
#6 | 1175232-6_page-title-revisions.patch | 6.22 KB | indytechcook |
#1 | 1175232-1-empty-title-update.patch | 601 bytes | girishmuraly |
Comments
Comment #1
girishmuraly CreditAttribution: girishmuraly commentedActually the update happens in page_title_node_update(), so the attached patch works for me. I am able to reset custom page titles to empty and that allows the default page title to get picked up. Please review.
Comment #2
rantebi CreditAttribution: rantebi commentedSo excited to submit my first bug fix,
I was just about to commit the exact same fix :)
So at least I'll mark this tested.
I hope I'm doing this correctly.
Comment #3
nicholasThompsonThat line is:
http://drupalcode.org/project/page_title.git/blob/077c20a353b10185b51804...
In fact, looking at the code now, it actually looks like it is not revision safe; all Page Title updates are stored against the Node ID, node the Revision ID. This is something which I should really address.... But altering the code would involve also including a major database update to convert all NID's into Revision ID's for the latest (and all previous?) nodes.
Comment #4
girishmuraly CreditAttribution: girishmuraly commentedI dont see much value in storing revisions of page titles. Its also an unnecessary space waster and goes against the principle you stated of not inserting empty rows into the table.
Comment #5
nicholasThompsonI'm not so sure - there is a big difference between storing blank rows and storing "versions" of Page Titles (it might be useful to keep an audit trail if, for example, you have an SEO Contractor who had updated your site).
Comment #6
indytechcook CreditAttribution: indytechcook commentedHere is a patch that stores the page_title against the vid and not the nid along with an update statement.
Cheers!