Plugin/Events/Content: Difference between revisions
From Joomla! Documentation
Added deprecation notice and link to Joomla Manual |
|||
| (19 intermediate revisions by 8 users not shown) | |||
| Line 1: | Line 1: | ||
{{version/tutor|2.5,3.x|alt=1.5|altlink=J1.5:Plugin/Events/Content|alttitle=this guide for old event names}} | {{version/tutor|2.5,3.x|alt=1.5|altlink=J1.5:Plugin/Events/Content|alttitle=this guide for old event names}} | ||
{{Warning|This page has been superseded and is no longer maintained. Please go to [https://manual.joomla.org/docs/building-extensions/plugins/plugin-events/content Joomla Manual ] instead}} | |||
Content events are triggered during the content creation process. The majority of these events are called in many views many components and modules - they are generally not specific for the com_content component. This list gives a brief description of each event, what their parameters are, and some examples of their use in core plugins. | Content events are triggered during the content creation process. The majority of these events are called in many views many components and modules - they are generally not specific for the com_content component. This list gives a brief description of each event, what their parameters are, and some examples of their use in core plugins. | ||
| Line 16: | Line 19: | ||
===Example=== | ===Example=== | ||
*<tt>[https://github.com/joomla/joomla-cms/blob/ | *<tt>[https://github.com/joomla/joomla-cms/blob/staging/plugins/content/emailcloak/emailcloak.php plugins/content/emailcloak/emailcloak.php]</tt> | ||
==onContentAfterTitle== | ==onContentAfterTitle== | ||
===Description=== | ===Description=== | ||
This event only exists in Joomla {{JVer|3.x}}. This is a request for information that should be placed between the content title and the content body. Although parameters are passed by reference, this is not the event to modify article data. Use | This event only exists in Joomla {{JVer|3.x}}. This is a request for information that should be placed between the content title and the content body. Although parameters are passed by reference, this is not the event to modify article data. Use onContentPrepare for that purpose. Note this event has special purpose in com_content for use in handling the introtext. | ||
===Parameters=== | ===Parameters=== | ||
See the | See the onContentPrepare event for additional discussion of these parameters. | ||
*<code>context</code> The context of the content being passed to the plugin - this is the component name and view - or name of module (e.g. com_content.article). Use this to check whether you are in the desired context for the plugin. | *<code>context</code> The context of the content being passed to the plugin - this is the component name and view - or name of module (e.g. com_content.article). Use this to check whether you are in the desired context for the plugin. | ||
*<code>&article</code> The article that is being rendered by the view. | *<code>&article</code> The article that is being rendered by the view. | ||
| Line 34: | Line 37: | ||
==onContentBeforeDisplay== | ==onContentBeforeDisplay== | ||
===Description=== | ===Description=== | ||
This is a request for information that should be placed immediately before the generated content. For views that generate HTML, this might include the use of styles that are specified as part of the content or related parameters. Although parameters are passed by reference, this is not the event to modify article data. Use | This is a request for information that should be placed immediately before the generated content. For views that generate HTML, this might include the use of styles that are specified as part of the content or related parameters. Although parameters are passed by reference, this is not the event to modify article data. Use onContentPrepare for that purpose. | ||
===Parameters=== | ===Parameters=== | ||
See the | See the onContentPrepare event for additional discussion of these parameters. Note that unlike onContentPrepare, these parameters are passed by value. | ||
*<code>context</code> The context of the content being passed to the plugin - this is the component name and view - or name of module (e.g. com_content.article). Use this to check whether you are in the desired context for the plugin. | *<code>context</code> The context of the content being passed to the plugin - this is the component name and view - or name of module (e.g. com_content.article). Use this to check whether you are in the desired context for the plugin. | ||
*<code>&article</code> The article that is being rendered by the view. | *<code>&article</code> The article that is being rendered by the view. | ||
| Line 47: | Line 50: | ||
===Example=== | ===Example=== | ||
*<tt>[https://github.com/joomla/joomla-cms/blob/ | *<tt>[https://github.com/joomla/joomla-cms/blob/staging/plugins/content/vote/vote.php#L17 plugins/content/vote/vote.php]</tt> | ||
==onContentAfterDisplay== | ==onContentAfterDisplay== | ||
===Description=== | ===Description=== | ||
This is a request for information that should be placed immediately after the generated content. For views that generate HTML, this might include the closure of styles that are specified as part of the content or related parameters. Although parameters are passed by reference, this is not the event to modify article data. Use | This is a request for information that should be placed immediately after the generated content. For views that generate HTML, this might include the closure of styles that are specified as part of the content or related parameters. Although parameters are passed by reference, this is not the event to modify article data. Use onContentPrepare for that purpose. | ||
===Parameters=== | ===Parameters=== | ||
See the | See the onContentPrepare event for additional discussion of these parameters. Note that unlike onContentPrepare, these parameters are passed by value. | ||
*<code>context</code> The context of the content being passed to the plugin - this is the component name and view - or name of module (e.g. com_content.article). Use this to check whether you are in the desired context for the plugin. | *<code>context</code> The context of the content being passed to the plugin - this is the component name and view - or name of module (e.g. com_content.article). Use this to check whether you are in the desired context for the plugin. | ||
*<code>&article</code> The article that is being rendered by the view. | *<code>&article</code> The article that is being rendered by the view. | ||
| Line 71: | Line 74: | ||
*<code>article</code> A reference to the JTableContent object that is being saved which holds the article data. | *<code>article</code> A reference to the JTableContent object that is being saved which holds the article data. | ||
*<code>isNew</code> A boolean which is set to true if the content is about to be created. | *<code>isNew</code> A boolean which is set to true if the content is about to be created. | ||
*<code>data</code> The data to save. Note this data should be already validated by the extension. Since {{JVer|3.7}}. Required to be set by extensions as of {{JVer|4.0}} as the core joomla content plugin uses this property | |||
===Return Value=== | ===Return Value=== | ||
| Line 99: | Line 104: | ||
===Example=== | ===Example=== | ||
*[https:// | *[https://github.com/joomla/joomla-cms/blob/staging/plugins/user/profile/profile.php#L234 plugins/user/profile/profile.php] | ||
==onContentPrepareData== | ==onContentPrepareData== | ||
| Line 113: | Line 118: | ||
===Example=== | ===Example=== | ||
*[https:// | *[https://github.com/joomla/joomla-cms/blob/staging/plugins/user/profile/profile.php#L68 plugins/user/profile/profile.php] | ||
==onContentBeforeDelete== | ==onContentBeforeDelete== | ||
| Line 145: | Line 150: | ||
==onContentChangeState== | ==onContentChangeState== | ||
===Description=== | ===Description=== | ||
This is an event that is called after content has | This is an event that is called after content has its state change (e.g. Published to Unpublished). | ||
===Parameters=== | ===Parameters=== | ||
| Line 159: | Line 164: | ||
==onContentSearch== | ==onContentSearch== | ||
===Description=== | |||
This event is triggered by a variety of search related operations. It is a request for a | |||
plugin to return the result of a search request. The rows must return the following fields, which are used in a common display routine: | |||
* browsernav | |||
* catslug | |||
* created | |||
* href | |||
* section | |||
* slug | |||
* text | |||
* title | |||
===Parameters=== | |||
* <code>$text</code> The target search string. | |||
* <code>$phrase</code> A string matching option (exact|any|all). Default is "any". | |||
* <code>$ordering</code> A string ordering option (newest|oldest|popular|alpha|category). Default is "newest". | |||
* <code>$areas</code> An array if restricted to areas, null if search all. | |||
===Return Value=== | |||
Array of stdClass objects with members as described above. | |||
===Used in files=== | |||
* <tt>[https://github.com/joomla/joomla-cms/blob/master/administrator/components/com_search/models/searches.php#L158 administrator/components/com_search/models/searches.php]</tt> | |||
* <tt>[https://github.com/joomla/joomla-cms/blob/master/components/com_search/models/search.php#L154 components/com_search/models/search.php]</tt> | |||
* <tt>[https://github.com/joomla/joomla-cms/blob/master/plugins/search/categories/categories.php#L62 plugins/search/categories/categories.php]</tt> | |||
* <tt>[https://github.com/joomla/joomla-cms/blob/master/plugins/search/contacts/contacts.php#L60 plugins/search/contacts/contacts.php]</tt> | |||
* <tt>[https://github.com/joomla/joomla-cms/blob/master/plugins/search/content/content.php#L53 plugins/search/content/content.php]</tt> | |||
* <tt>[https://github.com/joomla/joomla-cms/blob/master/plugins/search/newsfeeds/newsfeeds.php#L60 plugins/search/newsfeeds/newsfeeds.php]</tt> | |||
* <tt>[https://github.com/joomla/joomla-cms/blob/master/plugins/search/tags/tags.php#L60 plugins/search/tags/tags.php]</tt> | |||
* <tt>[https://github.com/joomla/joomla-cms/blob/master/plugins/search/weblinks/weblinks.php#L62 plugins/search/weblinks/weblinks.php]</tt> | |||
==onContentSearchAreas== | ==onContentSearchAreas== | ||
===Description=== | |||
This appears to be a request for plugins to identify which "areas" they provide | |||
search facilities for. | |||
===Parameters=== | |||
None. | |||
===Return Value=== | |||
An associative array of area names, indexed by the area identifier. For example, array( 'categories' => 'Categories' ). | |||
===Used in files=== | |||
* <tt>components/com_search/models/search.php</tt> | |||
* <tt>plugins/search/categories.php</tt> | |||
* <tt>plugins/search/contacts.php</tt> | |||
* <tt>plugins/search/content.php</tt> | |||
* <tt>plugins/search/newsfeeds.php</tt> | |||
* <tt>plugins/search/tags/tags.php</tt> | |||
* <tt>plugins/search/weblinks.php</tt> | |||
<noinclude>[[Category:Plugin Development]][[Category:Specifications]]</noinclude> | <noinclude>[[Category:Plugin Development]][[Category:Specifications]]</noinclude> | ||
Latest revision as of 08:54, 13 August 2024
This page has been superseded and is no longer maintained. Please go to Joomla Manual instead
Content events are triggered during the content creation process. The majority of these events are called in many views many components and modules - they are generally not specific for the com_content component. This list gives a brief description of each event, what their parameters are, and some examples of their use in core plugins.
onContentPrepare
Description
This is the first stage in preparing content for output and is the most common point for content orientated plugins to do their work. Since the article and related parameters are passed by reference, event handlers can modify them prior to display.
Parameters
contextThe context of the content being passed to the plugin - this is the component name and view - or name of module (e.g. com_content.article). Use this to check whether you are in the desired context for the plugin.&articleA reference to the article that is being rendered by the view (For example: the text of a com_content article can be found with $article->text).¶msA reference to an associative array of relevant parameters. The view determines what it considers to be relevant and passes that information along.pageAn integer that determines the "page" of the content that is to be generated. Note that in the context of views that might not generate HTML output, a page is a reasonably abstract concept that depends on the context.
Return Value
None. Results are returned by modifying the referenced arguments. Sometimes a boolean might be returned to check for success or failure of the event.
Example
onContentAfterTitle
Description
This event only exists in Joomla
. This is a request for information that should be placed between the content title and the content body. Although parameters are passed by reference, this is not the event to modify article data. Use onContentPrepare for that purpose. Note this event has special purpose in com_content for use in handling the introtext.
Parameters
See the onContentPrepare event for additional discussion of these parameters.
contextThe context of the content being passed to the plugin - this is the component name and view - or name of module (e.g. com_content.article). Use this to check whether you are in the desired context for the plugin.&articleThe article that is being rendered by the view.¶msAn associative array of relevant parameters.limitstartAn integer that determines the "page" of the content that is to be generated.
Return Value
String. Returned value from this event will be displayed in a placeholder. Most templates display this placeholder after the article separator.
onContentBeforeDisplay
Description
This is a request for information that should be placed immediately before the generated content. For views that generate HTML, this might include the use of styles that are specified as part of the content or related parameters. Although parameters are passed by reference, this is not the event to modify article data. Use onContentPrepare for that purpose.
Parameters
See the onContentPrepare event for additional discussion of these parameters. Note that unlike onContentPrepare, these parameters are passed by value.
contextThe context of the content being passed to the plugin - this is the component name and view - or name of module (e.g. com_content.article). Use this to check whether you are in the desired context for the plugin.&articleThe article that is being rendered by the view.¶msAn associative array of relevant parameters.limitstartAn integer that determines the "page" of the content that is to be generated.
Return Value
String. Returned value from this event will be displayed in a placeholder. Most templates display this placeholder after the article separator.
Example
onContentAfterDisplay
Description
This is a request for information that should be placed immediately after the generated content. For views that generate HTML, this might include the closure of styles that are specified as part of the content or related parameters. Although parameters are passed by reference, this is not the event to modify article data. Use onContentPrepare for that purpose.
Parameters
See the onContentPrepare event for additional discussion of these parameters. Note that unlike onContentPrepare, these parameters are passed by value.
contextThe context of the content being passed to the plugin - this is the component name and view - or name of module (e.g. com_content.article). Use this to check whether you are in the desired context for the plugin.&articleThe article that is being rendered by the view.¶msA JRegistry object of merged article and menu item params.limitstartAn integer that determines the "page" of the content that is to be generated.
Return Value
String. Returned value from this event will be displayed in a placeholder. Most templates display this placeholder after the article separator.
onContentBeforeSave
Description
This is an event that is called right before the content is saved into the database. You can abort the save by returning false. In the case of JModelLegacy for example the error will then be set by calling $this->setError($table->getError); to be displayed to user.
Parameters
contextThe context of the content being passed to the plugin - this is the component name and view - or name of module (e.g. com_content.article). Use this to check whether you are in the desired context for the plugin.articleA reference to the JTableContent object that is being saved which holds the article data.isNewA boolean which is set to true if the content is about to be created.dataThe data to save. Note this data should be already validated by the extension. Since
. Required to be set by extensions as of
as the core joomla content plugin uses this property
Return Value
Boolean. Result will affect the saving process. See description for details.
onContentAfterSave
Description
This is an event that is called after the content is saved into the database. Even though article object is passed by reference, changes will not be saved since storing data into database phase is past. An example use case would be redirecting user to the appropriate place after saving.
Parameters
contextThe context of the content being passed to the plugin - this is the component name and view - or name of module (e.g. com_content.article). Use this to check whether you are in the desired context for the plugin.articleA reference to the JTableContent object that is being saved which holds the article data.isNewA boolean which is set to true if the content is about to be created.
Return Value
None. Result will be omitted.
onContentPrepareForm
Description
Called before a JForm is rendered. It can be used to modify the JForm object in memory before rendering. For example, use JForm->loadFile() to add fields or JForm->removeField() to remove fields. Or use JForm->setFieldAttribute() or other JForm methods to modify fields for the form.
Parameters
formThe JForm object to be displayed. Use the $form->getName() method to check whether this is the form you want to work with.dataAn object containing the data for the form.
Return Value
booleanTrue if method succeeds.
Example
onContentPrepareData
Description
Called after the data for a JForm has been retrieved. It can be used to modify the data for a JForm object in memory before rendering. This is usually used in tandem with the onContentPrepareForm method - this event adds the data to the already altered JForm.
Parameters
contextThe context of the content being passed to the plugin - this is the component name and view - or name of module (e.g. com_content.article). Use this to check whether you are in the desired context for the plugin.dataAn object containing the data for the form.
Return Value
booleanTrue if method succeeds.
Example
onContentBeforeDelete
Description
This is an event that is called right before the content is deleted from the database. You can abort the delete by returning false. In the case of JModelLegacy for example the error will then be set by calling $this->setError($table->getError); to be displayed to user.
Parameters
contextThe context of the content being passed to the plugin - this is the component name and view - or name of module (e.g. com_content.article). Use this to check whether you are in the desired context for the plugin.dataA reference to the JTableContent object that is being deleted which holds the article data.
Return Value
Boolean. Result will affect the saving process. See description for details.
Example
onContentAfterDelete
Description
This is an event that is called after the content is deleted from the database. An example use case would be redirecting user to the appropriate place after deleting.
Parameters
contextThe context of the content being passed to the plugin - this is the component name and view - or name of module (e.g. com_content.article). Use this to check whether you are in the desired context for the plugin.articleA reference to the JTableContent object that has been deleted which holds the article data.
Return Value
None. Result will be omitted.
Example
onContentChangeState
Description
This is an event that is called after content has its state change (e.g. Published to Unpublished).
Parameters
contextThe context of the content being passed to the plugin - this is the component name and view - or name of module (e.g. com_content.article). Use this to check whether you are in the desired context for the plugin.$pksAn array of primary key ids of the content that has changed state.$valueThe value of the state that the content has been changed to.
Return Value
None. Result will be omitted.
Example
onContentSearch
Description
This event is triggered by a variety of search related operations. It is a request for a plugin to return the result of a search request. The rows must return the following fields, which are used in a common display routine:
- browsernav
- catslug
- created
- href
- section
- slug
- text
- title
Parameters
$textThe target search string.$phraseA string matching option (exact|any|all). Default is "any".$orderingA string ordering option (newest|oldest|popular|alpha|category). Default is "newest".$areasAn array if restricted to areas, null if search all.
Return Value
Array of stdClass objects with members as described above.
Used in files
- administrator/components/com_search/models/searches.php
- components/com_search/models/search.php
- plugins/search/categories/categories.php
- plugins/search/contacts/contacts.php
- plugins/search/content/content.php
- plugins/search/newsfeeds/newsfeeds.php
- plugins/search/tags/tags.php
- plugins/search/weblinks/weblinks.php
onContentSearchAreas
Description
This appears to be a request for plugins to identify which "areas" they provide search facilities for.
Parameters
None.
Return Value
An associative array of area names, indexed by the area identifier. For example, array( 'categories' => 'Categories' ).
Used in files
- components/com_search/models/search.php
- plugins/search/categories.php
- plugins/search/contacts.php
- plugins/search/content.php
- plugins/search/newsfeeds.php
- plugins/search/tags/tags.php
- plugins/search/weblinks.php