Pending

User tests: Successful: Unsuccessful:

avatar kheruc
kheruc
22 Aug 2013

The bug is that custom titles for articles set by a content plugin get overwritten with original article titles when the article has a parent category menu item. More info:
http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_id=8103&tracker_item_id=28052

avatar kheruc kheruc - open - 22 Aug 2013
avatar zero-24
zero-24 - comment - 22 Jan 2014

@kheruc
have you a sample plugin / code to test the change/fix?

Thanks :+1:

avatar Bakual
Bakual - comment - 22 Jan 2014

Yep, depends on what the plugin does if that is a bug or not. It may well be that the plugin tries to do something it isn't supposed to do. Or it uses the wrong events.

avatar kheruc
kheruc - comment - 24 Jan 2014

A content plugin is supposed to be able to adjust the article page title (the title that goes inside the title element), for example to append specific keywords to the title based on how the user configures the plugin.

This works fine when the article doesn't have a parent menu item (i.e. category blog menu item). But if the category menu item exists, the title gets overwritten.

This bug was introduced in the early versions of J1.6 and it's still here in the latest builds of J2.5 and J3.2.

In the components/com_content/views/article/view.html.php file you will find a block of code that starts with this comment:
// If this is not a single article menu item, set the page title to the article title

So, someone decided to overwrite the page title with the article title when it's not a single article menu item. They were trying to fix a different bug, but they've done it in a way that always overwrites the page title of the article if a category menu exists, regardless if the page title is already set or not.

The patch I provided fixes this (it checks if the page title is already set before overwriting it with article title) and it doesn't cause any new problems.

What exactly do you need to test this? Do you want me to create a sample content plugin?

avatar Bakual
Bakual - comment - 24 Jan 2014

A content plugin is supposed to be able to adjust the article page title (the title that goes inside the title element), for example to append specific keywords to the title based on how the user configures the plugin.

As said, it depends on which event it tries to do that. For example "onContentPrepare" would be the wrong one as this one is meant only for the actual content.

So, someone decided to overwrite the page title with the article title when it's not a single article menu item.

I'd say this is actually intended behavior.

Do you want me to create a sample content plugin?

I think that would help, yes. To see what the issue really is.

avatar kheruc
kheruc - comment - 24 Jan 2014

I uploaded the simplest version of the content plugin (plg_titleseo.zip) that modifies the article page title. You can download it in the Joomla tracker http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_id=8103&tracker_item_id=28052

You only need to publish it after installation.

The only thing that this plugin does is appends category title to the article page title. This works fine in articles that don't have a parent category menu item. If the category menu exists, the page title set by this plugin will be overwritten.

The plugin uses the "onContentBeforeDisplay" event to modify the page title.

The patch that I provided fixes the problem, but if someone has a better solution, let us know.

avatar Bakual
Bakual - comment - 24 Jan 2014

Imho the plugin uses the wrong event. The onContentBeforeDisplay is meant to generate HTML code which will be inserted just before the actual content. See https://github.com/joomla/joomla-cms/blob/staging/components/com_content/views/article/view.html.php#L159 for where it's called and what it does with the result.

What you want to do should not be done in a content related event. Those are not designed to interact with the document itself but with the content. To do what you want, you probably have to use onBeforeRender or something like that. You could still use the onContentBeforeDisplay (or maybe even better onContentPrepare?) event to catch the title and category and store it in the plugin and the recall it in a later event.

avatar kheruc
kheruc - comment - 24 Jan 2014

It doesn't work with any of the content events, but in my opinion it should work with the onContentBeforeDisplay event, as it does perfectly when the article doesn't have a menu for its category. This alone is a clear sign that there is a bug.

Anything is possible with a system plugin and system events, but that is not the optimal way to do it. A content plugin should be able to set a custom article page title. A system plugin would require an extra query to get the required information, while the content plugin already has all the necessary information.

The same content plugin was able to set the article page title in all versions of Joomla 1.5 and in first releases of Joomla 1.6. In one of the Joomla 1.6 releases someone made a change in the /com_content/views/article/view.html.php file that I pointed to, but they didn't test all scenarios related to page titles and that caused this problem.

avatar jmcameron
jmcameron - comment - 24 Jan 2014

On a related note, I recently noticed that for Category lists, almost identical calls to onContentPrepare are done for both the category title and the category description (see the JHtml::('content.prepare'... calls on lines 35 and 47 of layouts/joomla/content/categorydefault.php). That means there is no way to distinguish the category title from its description. So I agree that the onContentPrepare invocation for the title is probably wrong -- or at least needs some way to distinguish it from the similar call for the category description. My inclination would be to either eliminate the call for the title (which as added for 3.x) or add 'title' as the parameter for the first call so there is some way for content plugins to distinguish the category title from the description.

Added this as item [#33193] on the Joomla tracker: http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=33193

avatar Bakual
Bakual - comment - 24 Jan 2014

@jmcameron Can you open a new trackeritem for that please if you think it's a bug?

avatar Bakual
Bakual - comment - 24 Jan 2014

@kheruc onContentBeforeDisplay is really the wrong event. As said it's meant to generate HTML output which is displayed just before the article content. Like a voting plugin.
Do this instead in your plugin and it will work in all cases:

class plgContentTitleseo extends JPlugin
{
    static  $pagetitle;

    public function onContentPrepare($context, &$article, &$params)
    {
        self::$pagetitle = $article->title . ' in ' . $article->category_title;
    }

    public function onBeforeRender()
    {
        if (self::$pagetitle)
        {
            JFactory::getDocument()->title = self::$pagetitle;
        }
    }
}
avatar kheruc
kheruc - comment - 25 Jan 2014

Thanks for the alternative solution, it works.

avatar kheruc kheruc - change - 25 Jan 2014
Status New Closed
Closed_Date 0000-00-00 00:00:00 2014-01-25 15:26:45
avatar kheruc kheruc - close - 25 Jan 2014
avatar kheruc kheruc - close - 25 Jan 2014
avatar kheruc kheruc - head_ref_deleted - 25 Jan 2014
avatar kheruc
kheruc - comment - 25 Feb 2014

Actually, this isn't a good solution, the title can't be overwritten when Joomla cache is enabled, the onBeforeRender event runs after the article has been cached with the wrong page title.
Do you still think that onBeforeRender() is the correct event in this case?

avatar Bakual
Bakual - comment - 25 Feb 2014

When a page is cached, onContentPrepare doesn't get fired as well imho.

avatar kheruc
kheruc - comment - 25 Feb 2014

When the page is cached, it works fine with the onContentBeforeDisplay event (which my plugin used in Joomla 1.5 and 1.6 until the bug was introduced).

avatar Bakual
Bakual - comment - 25 Feb 2014

Does the cache not store the page title as well?

avatar kheruc
kheruc - comment - 26 Feb 2014

Cache stores the old page title before the onBeforeRender event runs. So, the example that you posted before doesn't work when cached page is loaded.

avatar Bakual
Bakual - comment - 26 Feb 2014

Sounds more like an issue with Cache then to me. Imho it should cache the fully rendered page.
One would have dive into the plugin events to see where exactly caching is triggered and if there is a possible event before that.

Add a Comment

Login with GitHub to post a comment