Plugin/Events/Content

From Joomla! Documentation

< Plugin‎ | Events
Stop hand nuvola.svg.png
Warning!

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[edit]

Description[edit]

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[edit]

  • context 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.
  • &article A 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).
  • &params A reference to an associative array of relevant parameters. The view determines what it considers to be relevant and passes that information along.
  • page An 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[edit]

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[edit]

onContentAfterTitle[edit]

Description[edit]

This event only exists in Joomla Joomla 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[edit]

See the onContentPrepare event for additional discussion of these parameters.

  • context 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.
  • &article The article that is being rendered by the view.
  • &params An associative array of relevant parameters.
  • limitstart An integer that determines the "page" of the content that is to be generated.

Return Value[edit]

String. Returned value from this event will be displayed in a placeholder. Most templates display this placeholder after the article separator.

onContentBeforeDisplay[edit]

Description[edit]

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[edit]

See the onContentPrepare event for additional discussion of these parameters. Note that unlike onContentPrepare, these parameters are passed by value.

  • context 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.
  • &article The article that is being rendered by the view.
  • &params An associative array of relevant parameters.
  • limitstart An integer that determines the "page" of the content that is to be generated.

Return Value[edit]

String. Returned value from this event will be displayed in a placeholder. Most templates display this placeholder after the article separator.

Example[edit]

onContentAfterDisplay[edit]

Description[edit]

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[edit]

See the onContentPrepare event for additional discussion of these parameters. Note that unlike onContentPrepare, these parameters are passed by value.

  • context 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.
  • &article The article that is being rendered by the view.
  • &params A JRegistry object of merged article and menu item params.
  • limitstart An integer that determines the "page" of the content that is to be generated.

Return Value[edit]

String. Returned value from this event will be displayed in a placeholder. Most templates display this placeholder after the article separator.

onContentBeforeSave[edit]

Description[edit]

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[edit]

  • context 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.
  • article A reference to the JTableContent object that is being saved which holds the article data.
  • isNew A boolean which is set to true if the content is about to be created.
  • data The data to save. Note this data should be already validated by the extension. Since Joomla 3.7. Required to be set by extensions as of Joomla 4.0 as the core joomla content plugin uses this property


Return Value[edit]

Boolean. Result will affect the saving process. See description for details.

onContentAfterSave[edit]

Description[edit]

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[edit]

  • context 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.
  • article A reference to the JTableContent object that is being saved which holds the article data.
  • isNew A boolean which is set to true if the content is about to be created.

Return Value[edit]

None. Result will be omitted.

onContentPrepareForm[edit]

Description[edit]

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[edit]

  • form The JForm object to be displayed. Use the $form->getName() method to check whether this is the form you want to work with.
  • data An object containing the data for the form.

Return Value[edit]

  • boolean True if method succeeds.

Example[edit]

onContentPrepareData[edit]

Description[edit]

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[edit]

  • context 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.
  • data An object containing the data for the form.

Return Value[edit]

  • boolean True if method succeeds.

Example[edit]

onContentBeforeDelete[edit]

Description[edit]

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[edit]

  • context 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.
  • data A reference to the JTableContent object that is being deleted which holds the article data.

Return Value[edit]

Boolean. Result will affect the saving process. See description for details.

Example[edit]

onContentAfterDelete[edit]

Description[edit]

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[edit]

  • context 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.
  • article A reference to the JTableContent object that has been deleted which holds the article data.

Return Value[edit]

None. Result will be omitted.

Example[edit]

content/finder/finder.php

onContentChangeState[edit]

Description[edit]

This is an event that is called after content has its state change (e.g. Published to Unpublished).

Parameters[edit]

  • context 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.
  • $pks An array of primary key ids of the content that has changed state.
  • $value The value of the state that the content has been changed to.

Return Value[edit]

None. Result will be omitted.

Example[edit]

content/finder/finder.php

onContentSearch[edit]

Description[edit]

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[edit]

  • $text The target search string.
  • $phrase A string matching option (exact|any|all). Default is "any".
  • $ordering A string ordering option (newest|oldest|popular|alpha|category). Default is "newest".
  • $areas An array if restricted to areas, null if search all.

Return Value[edit]

Array of stdClass objects with members as described above.

Used in files[edit]

onContentSearchAreas[edit]

Description[edit]

This appears to be a request for plugins to identify which "areas" they provide search facilities for.

Parameters[edit]

None.

Return Value[edit]

An associative array of area names, indexed by the area identifier. For example, array( 'categories' => 'Categories' ).

Used in files[edit]

  • 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