[Modules] Calling content plugin into module

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
nwl
Joomla! Apprentice
Joomla! Apprentice
Posts: 28
Joined: Thu Feb 09, 2012 11:27 am
Location: Wakanda
Contact:

[Modules] Calling content plugin into module

Post by nwl » Fri Jul 01, 2016 9:20 am

Hi all,

I'm porting a code from a template override of com_content category blog_item into a module.
Everything is all right done, except for one thing I'm struggling with.

I have this code working in com_content tmpl

Code: Select all

<?php echo $this->item->event->beforeDisplayContent; ?>
In module I tried:

Code: Select all

<?php echo $item->event->beforeDisplayContent; ?>
But it is not working and it fires a notice ("Notice: Trying to get property of non-object...")

Any suggestion to have it working into a module?

User avatar
dhuelsmann
Joomla! Master
Joomla! Master
Posts: 19659
Joined: Sun Oct 02, 2005 12:50 am
Location: Omaha, NE
Contact:

Re: [Modules] Calling content plugin into module

Post by dhuelsmann » Fri Jul 01, 2016 6:31 pm

Perhaps include the reference to the object, i.e. $this
Regards, Dave
Past Treasurer Open Source Matters, Inc.
Past Global Moderator
http://www.kiwaniswest.org

sovainfo
Joomla! Exemplar
Joomla! Exemplar
Posts: 8808
Joined: Sat Oct 01, 2011 7:06 pm

Re: [Modules] Calling content plugin into module

Post by sovainfo » Fri Jul 01, 2016 7:30 pm

Doubt that the module is using the component views. That means these attributes are not available. It is the view.html.php of each view in the content component that triggers these events and add these attributes.
Issue with migrating? Include logs/joomla_update.php in your report!
Blank screen? Verify pagesource for HTML code (javascript error)
Installation failing on populating database? Install with set_time_limit(0)
Document your customizations!

nwl
Joomla! Apprentice
Joomla! Apprentice
Posts: 28
Joined: Thu Feb 09, 2012 11:27 am
Location: Wakanda
Contact:

Re: [Modules] Calling content plugin into module

Post by nwl » Sat Jul 02, 2016 3:36 pm

I found a solution, thanks to this suggestion: http://joomla.stackexchange.com/questio ... o-a-module

As sovainfo said it's the view.html.php

So I added this into my helper.php

Code: Select all

$dispatcher = JEventDispatcher::getInstance();
PluginHelper::importPlugin('content');
Then I added this into an existing loop:

Code: Select all

foreach ($items as &$item)
	{
	$item->event = new stdClass();				 
	$item->event->beforeDisplayContent = trim(implode("\n", $results));
			 
	$results = $dispatcher->trigger('afterDisplayTitle', array('com_content.article', &$item, &$item->params, 0)); 
	$item->event->afterDisplayTitle = trim(implode("\n", $results));
			 
	$results = $dispatcher->trigger('afterDisplayContent', array('com_content.article', &$item, &$item->params, 0)); 
	$item->event->afterDisplayContent = trim(implode("\n", $results));	
		
	}
And now in my tmpl/default.php I can use:

Code: Select all

<?php echo $item->event->beforeDisplayContent; ?>


Locked

Return to “Joomla! 3.x Coding”