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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

girishmuraly’s picture

Status: Active » Needs review
FileSize
601 bytes

Actually 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.

rantebi’s picture

Status: Needs review » Reviewed & tested by the community

So 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.

nicholasThompson’s picture

That line is:

  1. Leftover from D6 where that section includes an INSERT eg:
    http://drupalcode.org/project/page_title.git/blob/077c20a353b10185b51804...
  2. Intentional functionality. We dont want to insert empty rows into the table; a "missing" entry for a Node ID is considered blank

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.

girishmuraly’s picture

Title: Unable to set empty page title in new revision » Page Title not Node Revision Safe
Status: Reviewed & tested by the community » Needs work

I 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.

nicholasThompson’s picture

I'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).

indytechcook’s picture

Version: 7.x-2.4-beta1 » 7.x-2.x-dev
Category: bug » feature
Status: Needs work » Needs review
FileSize
6.22 KB

Here is a patch that stores the page_title against the vid and not the nid along with an update statement.

Cheers!