You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/building-extensions/plugins/basic-content-plugin.md
+56-47Lines changed: 56 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,14 +19,25 @@ In addition, the plugin demonstrates the use of:
19
19
- language constants - both in the manifest file and in the plugin code
20
20
- returning a value from a plugin method - through the use of the `onContentAfterTitle` event. The plugin code adds some text after the article title.
21
21
22
-
You can test this plugin on both Joomla 4 and Joomla 5 instances, to see the differences in obtaining the parameters and returning the result (as described in [Joomla 4 and 5 changes](joomla-4-and-5-changes.md)).
22
+
The diagram below lists the plugin files to write, or you can download the plugin
23
+
from the Joomla Manual Examples repository [shortcodes plugin](https://github.com/joomla/manual-examples/tree/main/plugin-example-shortcode).
The diagram shows the plugin files to write, or you can download a zip file of the plugin from [shortcodes plugin download](_assets/plg_shortcodes.zip).
25
+
```
26
+
plg_shortcodes
27
+
├─── language
28
+
│ └─── en-GB
29
+
│ ├─── plg_content_shortcodes.ini
30
+
│ └─── plg_content_shortcodes.sys.ini
31
+
├─── services
32
+
│ └─── provider.php
33
+
├─── src
34
+
│ └─── Extension
35
+
│ └─── Shortcode.php
36
+
└─── shortcodes.xml
37
+
```
27
38
28
39
## Manifest File
29
-
For general information on manifest files see [Manifest Files](https://docs.joomla.org/Manifest_files).
40
+
For general information on manifest files see [Manifest Files](../install-update/installation/manifest.md).
30
41
31
42
```xml title="plg_shortcodes/shortcodes.xml"
32
43
<?xml version="1.0" encoding="utf-8"?>
@@ -36,7 +47,7 @@ For general information on manifest files see [Manifest Files](https://docs.joom
Previous sections described plugin types as 'content', 'system', etc but here the `type` is "plugin" (as it's the type of the extension) and the `group` refers to the plugin type.
72
+
Here the `type` is "plugin" (as it's the type of the extension) and the `group` refers to the plugin type.
62
73
63
74
### Language constants
64
75
@@ -156,7 +167,7 @@ This is pretty much boilerplate code for obtaining your plugin from the Dependen
156
167
use My\Plugin\Content\Shortcodes\Extension\Shortcode;
157
168
```
158
169
159
-
Ensure that this aligns with your `<namespace>` in the manifest file and your `namespace` statement and class name in the Extension class file. .
170
+
Ensure that this aligns with your `<namespace>` in the manifest file and your `namespace` statement and class name in the Extension class file.
@@ -172,16 +183,7 @@ Ensure that this matches your class in your `src/Extension` directory.
172
183
173
184
### Extension Class
174
185
This is the main code of the plugin. Hopefully the comments in the code explain what is going on.
175
-
176
-
As explained in [Joomla 4 and 5 changes](./joomla-4-and-5-changes.md), code which triggers the Events can use a `GenericEvent` or a concrete Event, eg `ContentPrepareEvent`. In both these cases you can get the arguments using
but you have to check in your code how to return the result.
183
-
184
-
Using this approach means that you don't need to change your plugin code if the code which is triggering the event changes from using a generic Event class to a concrete event class.
186
+
For further details see the page on [Plugin Methods and Arguments](./methods-and-arguments.md).
PLG_CONTENT_SHORTCODES_NO_MATCH="Error: no match for shortcode found"
310
+
PLG_CONTENT_SHORTCODES_PROCESSED="Processed for shortcodes"
311
+
PLG_CONTENT_SHORTCODES_NOT_PROCESSED="Not processed for shortcodes"
305
312
```
306
313
307
314
## Installation
@@ -313,4 +320,6 @@ On my Joomla instance {sitename} the default editor is {editor}.
313
320
```
314
321
Then navigate to a Joomla site menuitem which displays this article, either as a single article or as one of the featured articles.
315
322
316
-
The code should work on both Joomla 4 and Joomla 5, and should also display after the article title information about the type of event class used, and how the value is returned.
323
+
Include a non-existent configuration parameter in your shortcode to display the error text.
324
+
325
+
Also compare the subtitle shown for a page displaying an article with a page displaying a contact.
@@ -20,6 +26,8 @@ The process of involving the plugins comprises 2 steps:
20
26
1. Import all plugins of a given type
21
27
2. Trigger an event
22
28
29
+
## Importing a Plugin
30
+
23
31
Importing a plugin type is implemented by the code:
24
32
```php
25
33
PluginHelper::importPlugin($pluginType, …);
@@ -36,12 +44,16 @@ Importing a plugin type involves:
36
44
37
45
Splitting the plugins by plugin type in this way makes Joomla more performant - it doesn't need to process plugins which aren't going to be interested in the event which will be triggered next.
38
46
47
+
## Triggering an Event
48
+
39
49
The second step is triggering an event via a call to the event dispatcher. Joomla looks through its store of `Listeners` to determine which plugins have subscribed to that event type. It then calls the associated method of the subscribing plugin, and passes the event data to it, often allowing that data to be modified by the plugin code.
40
50
41
51
Each plugin which has subscribed to that event is called in turn (based on a priority scheme), and any results returned by the plugins are collated into an array associated with the event.
42
52
43
53
As an example, after Joomla is initialised system plugins are imported and the event `onAfterInitialise` is triggered. The "Remember Me" plugin (in plugins/system/remember) receives notification of this, and can log in a user who has previously checked the "Remember Me" checkbox on the login form.
44
54
55
+
## Subsequent Events
56
+
45
57
Once a plugin has been imported and its subscriptions logged in the `Listeners` data store, then it continues to receive notifications for all the events it has subscribed to. For example, consider the following scenario:
46
58
- system plugins are imported, and the `onAfterInitialise` event is triggered
47
59
- some time later content plugins are imported, and the `onContentPrepare` event is triggered.
@@ -50,6 +62,8 @@ The system plugins imported in the first step can subscribe to the `onContentPre
50
62
51
63
You should also be aware that unlike components and modules, there aren't different site plugins and administrator plugins. The plugins which you install are run for all the different contexts - site, administrator and API applications - so it's a good idea to in your plugins to check the application context.
52
64
65
+
## Sequence Diagram
66
+
53
67
For those who wish a more detailed picture of how plugins work, see the sequence diagram below.
0 commit comments