Class 'ContentHelperRoute' not found

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
User avatar
bascherz
Joomla! Explorer
Joomla! Explorer
Posts: 257
Joined: Mon Jan 16, 2006 1:33 am
Location: Vienna, VA
Contact:

Class 'ContentHelperRoute' not found

Post by bascherz » Fri Apr 20, 2018 1:15 am

The following code is in a plugin I just wrote. It works perfectly on one of my sites but causes an error on the other site. Both sites are running on the same server in the same hosting account with all the same system configuration. The sites are even setup nearly identically, even using the same template configured the same way. I can't think of why it would work in one case and not the other.

The following code is in an event handler for the onContentAfterSave event for my plugin. &$article is one of the parameters passed in.

Code: Select all

$article_link = JURI::base().JRoute::_(ContentHelperRoute::getArticleRoute($article->id,$article->catid));
Here's the error I get on one site but not the other (the above call works on the other site):

Code: Select all

Class 'ContentHelperRoute' not found
Can anyone tell me what could cause the above error? Clearly, the same plugin installed on two nearly identical sites should work on both sites, right?

Thanks in advance,
Bruce

Edit: Something just hit me while I was typing that. On the site it is working, I was editing my article on the site front end and on the other I was editing on the back end. So I tried editing the article in the back end on both sites and the error occurs on both sites in that case. So it would seem that class ContentHelperRoute is not being loaded when in the admin back end of the site. Interesting. Is that something that should be fixed in the core or should my plugin be doing something to prevent it?

I added the following line to prevent this error, but this is not needed if the article is being edited on the site front end. This prevents the error from occurring, but now the generated link is completely wrong.

Code: Select all

if(!class_exists('ContentHelperRoute')) require_once (JPATH_SITE . '/components/com_content/helpers/route.php');
Bruce Scherzinger

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2906
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Class 'ContentHelperRoute' not found

Post by SharkyKZ » Fri Apr 20, 2018 7:36 am

bascherz wrote: I added the following line to prevent this error, but this is not needed if the article is being edited on the site front end. This prevents the error from occurring, but now the generated link is completely wrong.

Code: Select all

if(!class_exists('ContentHelperRoute')) require_once (JPATH_SITE . '/components/com_content/helpers/route.php');
Can you post examples of links generated before and after you added the code?

User avatar
bascherz
Joomla! Explorer
Joomla! Explorer
Posts: 257
Joined: Mon Jan 16, 2006 1:33 am
Location: Vienna, VA
Contact:

Re: Class 'ContentHelperRoute' not found

Post by bascherz » Fri Apr 20, 2018 12:56 pm

More detail. Sorry, I was rushed yesterday. I know you need this.

J! version: 3.8.6 (just updated to .7, no change)

There was no link before adding that last require_once line. The plugin was crashing on article saves in the back end because the class wasn't found. But, below shows the difference between the link produced when the plugin is triggered by saving an article from the front end vs. the back end with that require_once line inserted. These are both from saving the very same article. Please note I have SEF URLs enabled in global config.

Front:

Code: Select all

https://mydomain.com//home-sp-1432435916/hoa-board-news/this-is-a-test-article
Back:

Code: Select all

https://mydomain.com/administrator//administrator/index.php?option=com_content&view=article&id=74&catid=160
I added a line following the one that generates the link to remove "/administrator" from it and then both of the links do go to the correct article.

Code: Select all

https://mydomain.com//index.php?option=com_content&view=article&id=74&catid=160
But shouldn't this work the same in the front and back?
Bruce Scherzinger

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2906
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Class 'ContentHelperRoute' not found

Post by SharkyKZ » Fri Apr 20, 2018 1:18 pm

Routing between admin and site doesn't work yet https://github.com/joomla/joomla-cms/issues/20070.

It might get implemented in 3.9 https://github.com/joomla/joomla-cms/pull/16879.

But that will probably require changes in ContentHelperRoute too for this to work properly.

User avatar
bascherz
Joomla! Explorer
Joomla! Explorer
Posts: 257
Joined: Mon Jan 16, 2006 1:33 am
Location: Vienna, VA
Contact:

Re: Class 'ContentHelperRoute' not found

Post by bascherz » Fri Apr 20, 2018 2:08 pm

Awesome. Thanks for the info. Hope this was helpful. I at least have a solution that works now. I'll look forward to 3.9.
Bruce Scherzinger

User avatar
bascherz
Joomla! Explorer
Joomla! Explorer
Posts: 257
Joined: Mon Jan 16, 2006 1:33 am
Location: Vienna, VA
Contact:

Re: Class 'ContentHelperRoute' not found

Post by bascherz » Sat Apr 21, 2018 5:45 am

Just realized I am having a similar problem with content preparation. I posted about this elsewhere in these forums (viewtopic.php?f=727&t=961192), but at the time I had that problem I was only saving articles in the back end editor. I just tried editing one in the front end that uses the loadposition plugin and content.prepare worked. So it would appear there are many content things that don't render properly in the back end based on what I read at the URLs you provided, SharkyKZ. Guess I have to hope for all this stuff to be resolved in 3.9.

I'll end it here so it doesn't go off in a different direction. Thanks again for the info, SharkyKZ.
Bruce Scherzinger

User avatar
bascherz
Joomla! Explorer
Joomla! Explorer
Posts: 257
Joined: Mon Jan 16, 2006 1:33 am
Location: Vienna, VA
Contact:

Re: Class 'ContentHelperRoute' not found

Post by bascherz » Thu Mar 28, 2019 1:56 am

Wondering if any progress has been made on this. It it doesn't do in 3.9.4 what I had hoped. Didn't want to turn Github into a discussion forum, so I came back here.

My workaround, though it does generate both absolute and relative links for admin article saves that work, does not yield SEF URL, so the article is not in the same visual context as what the front end link provides. Here's the code I have that basically works right now:

Code: Select all

        // Build article links
        $rel_link = str_replace('/administrator','',JRoute::_(ContentHelperRoute::getArticleRoute($article->id,$article->catid)));
        $abs_link = str_replace('/administrator','',JURI::base().$rel_link);
        $abs_link = str_replace(':/','://',str_replace('//','/',$abs_link));
For instance, here are examples of front and back end URLs generated by the above code:

Front:

Code: Select all

https://mydomain/helpme/training-videos
Back:

Code: Select all

https://mydomain/index.php?option=com_content&view=article&id=26&catid=18
I have tried the new JRoute::link method with $client='site' but it doesn't do the job if I pass it the URL generated by ContentHelperRoute::getArticleRoute($article->id,$article->catid), which literally changes the front end SEF URL you see above to look like the back end link. Yeah, the links work. But is this progress?

Bruce
Bruce Scherzinger

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2906
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Class 'ContentHelperRoute' not found

Post by SharkyKZ » Thu Mar 28, 2019 6:44 am

I can't reproduce your result. JRoute::link() works fine for me.

Code: Select all

// Register route helper.
JLoader::register('ContentHelperRoute', JPATH_SITE . '/components/com_content/helpers/route.php');

// Check whether we are on SSL connection.
$ssl = JUri::getInstance()->isSsl() ? 1 : -1;

// Build an absolute link to the article on site.
$link = JRoute::link('site', ContentHelperRoute::getArticleRoute($article->id, $article->catid, $article->language), false, $ssl);


Locked

Return to “Joomla! 3.x Coding”