API16

Difference between revisions of "JDispatcher/trigger"

From Joomla! Documentation

< API16:JDispatcher
(New page: ===Description=== Triggers an event by dispatching arguments to all observers that handle the event and returning their return values. <span class="editsection" style="font-size:76%;"> ...)
 
m (preparing for archive only)
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
Triggers an event by dispatching arguments to all observers that handle the event and returning their return values.
 
Triggers an event by dispatching arguments to all observers that handle the event and returning their return values.
  
<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[Description:JDispatcher/trigger|Edit Descripton]]<nowiki>]</nowiki>
 
</span>
 
  
{{Description:JDispatcher/trigger}}
+
 
 +
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 80: Line 78:
 
</source>
 
</source>
  
<span class="editsection" style="font-size:76%;">
+
 
<nowiki>[</nowiki>[[SeeAlso:JDispatcher/trigger|Edit See Also]]<nowiki>]</nowiki>
+
<! removed transcluded page call, red link never existed >
</span>
 
{{SeeAlso:JDispatcher/trigger}}
 
  
 
===Examples===
 
===Examples===
<CodeExamplesForm />
+
=== Code Examples ===
 
<dpl>
 
<dpl>
 
  noresultsheader=\n
 
  noresultsheader=\n
 
  category=trigger
 
  category=trigger
 
  category=JDispatcher
 
  category=JDispatcher
  category=CodeExample
+
  namespace=CodeExample
 
  category=MethodExample
 
  category=MethodExample
 
  include=*
 
  include=*
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API16]]

Latest revision as of 20:30, 24 March 2017

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Triggers an event by dispatching arguments to all observers that handle the event and returning their return values.


<! removed transcluded page call, red link never existed >

Syntax[edit]

trigger($event, $args=array())
Parameter Name Default Value Description
$event $event The event to trigger.
$args array() $args An array of arguments.

Returns[edit]

array An array of results from each function call.

Defined in[edit]

libraries/joomla/event/dispatcher.php

Importing[edit]

jimport( 'joomla.event.dispatcher' );

Source Body[edit]

public function trigger($event, $args = array())
{
        // Initialise variables.
        $result = array();

        /*
         * If no arguments were passed, we still need to pass an empty array to
         * the call_user_func_array function.
         */
        if (!is_array($args)) {
                $args = (array)$args;
        }

        $event = strtolower($event);

        // Check if any plugins are attached to the event.
        if (!isset($this->_methods[$event]) || empty($this->_methods[$event])) {
                // No Plugins Associated To Event!
                return $result;
        }

        // Loop through all plugins having a method matching our event
        foreach ($this->_methods[$event] AS $key)
        {
                // Check if the plugin is present.
                if (!isset($this->_observers[$key])) {
                        continue;
                }

                // Fire the event for an object based observer.
                if (is_object($this->_observers[$key])) {
                        $args['event'] = $event;
                        $result[] = $this->_observers[$key]->update($args);
                }
                // Fire the event for a function based observer.
                elseif (is_array($this->_observers[$key])) {
                        $result[] = call_user_func_array($this->_observers[$key]['handler'], $args);
                }
        }

        return $result;
}


<! removed transcluded page call, red link never existed >

Examples[edit]

Code Examples[edit]