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
Returne/write value FROM à plugin TO à module ?
Moderators: ooffick, General Support Moderators
Forum rules
-
- Joomla! Apprentice
- Posts: 31
- Joined: Wed Feb 02, 2022 10:57 am
- pe7er
- Joomla! Master
- Posts: 24986
- Joined: Thu Aug 18, 2005 8:55 pm
- Location: Nijmegen, Netherlands
- Contact:
Re: Returne/write value FROM à plugin TO à module ?
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.
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
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com
-
- Joomla! Apprentice
- Posts: 31
- Joined: Wed Feb 02, 2022 10:57 am
Re: Returne/write value FROM à plugin TO à module ?
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
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
-
- Joomla! Hero
- Posts: 2910
- Joined: Fri Jul 05, 2013 10:35 am
- Location: Parts Unknown
Re: Returne/write value FROM à plugin TO à module ?
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.
-
- Joomla! Apprentice
- Posts: 31
- Joined: Wed Feb 02, 2022 10:57 am
Re: Returne/write value FROM à plugin TO à module ?
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
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
-
- Joomla! Hero
- Posts: 2910
- Joined: Fri Jul 05, 2013 10:35 am
- Location: Parts Unknown
Re: Returne/write value FROM à plugin TO à module ?
My bad, you're right. Plugin is still necessary in this case.
To trigger a plugin event in the module:
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:
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.:Is There API to cache datas?
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;
}
Code: Select all
$footnotes = $app->triggerEvent('onMyCustomPluginCollectFootnotes');
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;
}
}
-
- Joomla! Apprentice
- Posts: 31
- Joined: Wed Feb 02, 2022 10:57 am
Re: Returne/write value FROM à plugin TO à module ?
OK, I didn't translate "cache" that way . I will se that this week end. Thanks a lot