Returne/write value FROM à plugin TO à 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
Post Reply
slhuilli
Joomla! Apprentice
Joomla! Apprentice
Posts: 31
Joined: Wed Feb 02, 2022 10:57 am

Returne/write value FROM à plugin TO à module ?

Post by slhuilli » Tue May 02, 2023 5:28 pm

Hi

Is there a solution, an API to write/return text value inside a plugin into another module ?
Theses 2 element will work together in my project
I don't know how I can find that in the doc

Thanks

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 24986
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: Returne/write value FROM à plugin TO à module ?

Post by pe7er » Tue May 09, 2023 7:35 am

What are you trying to accomplish?

I've programmed a module that displays filter fields.
When you select some filters, it will refresh the URL and add the filters as parameters to the URL.
And I developed a plugin that uses those URL parameters to filter the content on the page.
So extensions can work together.
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

slhuilli
Joomla! Apprentice
Joomla! Apprentice
Posts: 31
Joined: Wed Feb 02, 2022 10:57 am

Re: Returne/write value FROM à plugin TO à module ?

Post by slhuilli » Tue May 09, 2023 5:05 pm

Hello,

In fact, I want to develop a very simple plugin in order to show a the bottom of the current article, all words with a foot notes
Firdt, I wanted to "read" $article->text and grep with regex ALL tags of "footnote" (it will be translated into french : {note-bas-de-page} ) in order to number the notes.
In a second time, I want to write a module to "grep" all theses notes of all articles in order to write a table of note in another article.
That's while I wanted to write from my plugin, the datas grepped and write it in a module.
I want to use a module to benefit from the configuration of the configuration of its position on the page

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

Re: Returne/write value FROM à plugin TO à module ?

Post by SharkyKZ » Wed May 10, 2023 5:19 am

Components are rendered before modules so this is possible. There are many ways to do this, depending on whether you're also developing a module or using something like mod_custom with shortcodes. Either way, you would need to cache the data collected in the plugin and then use it in the module. Another way is not to use the plugin at all and instead perform everything in the module. This would be at the cost of extra database queries as the module would need to get the current article.

slhuilli
Joomla! Apprentice
Joomla! Apprentice
Posts: 31
Joined: Wed Feb 02, 2022 10:57 am

Re: Returne/write value FROM à plugin TO à module ?

Post by slhuilli » Wed May 10, 2023 5:32 am

Hi and thanks for help me.
I'd like to write a content plugin White a shortcode because it Will be simplier for me to use it where I want. But your idea to read from database is interessant to.... if I found thé table/field....

Is There API to cache datas?

Thanks

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

Re: Returne/write value FROM à plugin TO à module ?

Post by SharkyKZ » Wed May 10, 2023 6:47 am

My bad, you're right. Plugin is still necessary in this case.
Is There API to cache datas?
By caching I meant use some sort of class-level cache to make the data collected by plugin available later in the module. There are many ways to implement this. A very simple way is to trigger a plugin event in the module. Inside the plugin you would write the collected data to a property and then return it in the custom event, e.g.:

Code: Select all

public function onContentPrepare($context, $item, $params, $page = 0)
{
	// Your logic to collect the footnotes.
	
	// Write them to a class property for later use.
	$this->footnotes = $footnotes;
}

public function onMyCustomPluginCollectFootnotes()
{
	return $this->footnotes;
}
To trigger a plugin event in the module:

Code: Select all

$footnotes = $app->triggerEvent('onMyCustomPluginCollectFootnotes');
Do note that the event name should be unique (e.g. include your vendor name) to prevent other plugins from butting in.

Another way is to use static caching. E.g. in your module helper class or in the plugin, or really any custom class:

Code: Select all

abstract class ModMyModuleHelper
{
	private static $footnotes;
	
	public static function setFootnotes($footnotes)
	{
		self::$footnotes = $footnotes;
	}
	
	public static function getFootnotes()
	{
		return self::$footnotes;
	}
}

slhuilli
Joomla! Apprentice
Joomla! Apprentice
Posts: 31
Joined: Wed Feb 02, 2022 10:57 am

Re: Returne/write value FROM à plugin TO à module ?

Post by slhuilli » Wed May 10, 2023 4:47 pm

OK, I didn't translate "cache" that way . I will se that this week end. Thanks a lot


Post Reply

Return to “Joomla! 3.x Coding”