Since: 1.5

abstract class CMSPlugin implements DispatcherAwareInterface, PluginInterface, LanguageAwareInterface

Plugin Class

Traits

DispatcherAwareTrait

Defines the trait for a language aware class.

Properties

Registry Since: 1.5
$params

A Registry object holding the parameters for the plugin

protected string Since: 1.5
$_name

The name of the plugin

protected string Since: 1.5
$_type

The plugin type

protected bool Since: 3.1
$autoloadLanguage

Affects constructor behavior. If true, language files will be loaded automatically.

protected bool deprecated Since: 4.0.0
$allowLegacyListeners

Should I try to detect and register legacy event listeners, i.e. methods which accept unwrapped arguments? While this maintains a great degree of backwards compatibility to Joomla! 3.x-style plugins it is much slower. You are advised to implement your plugins using proper Listeners, methods accepting an AbstractEvent as their sole parameter, for best performance. Also bear in mind that Joomla! 5.x onwards will only allow proper listeners, removing support for legacy Listeners.

Methods

getLanguage() deprecated

Get the Language.

void
setLanguage(Language $language) deprecated

Set the language to use.

__construct(array $config = [])

Constructor

bool
loadLanguage(string $extension = '', string $basePath = JPATH_ADMINISTRATOR)

Loads the plugin language file

void
registerListeners()

Registers its listeners.

void
registerLegacyListener(string $methodName)

Registers a legacy event listener, i.e. a method which accepts individual arguments instead of an AbstractEvent in its arguments. This provides backwards compatibility to Joomla! 3.x-style plugins.

void
registerListener(string $methodName)

Registers a proper event listener, i.e. a method which accepts an AbstractEvent as its sole argument. This is the preferred way to implement plugins in Joomla! 4.x and will be the only possible method with Joomla! 5.x onwards.

CMSApplicationInterface|null
getApplication()

Returns the internal application or null when not set.

void
setApplication(CMSApplicationInterface $application)

Sets the application to use.

$this
setDispatcher(DispatcherInterface $dispatcher) deprecated

Set the dispatcher to use.

DispatcherInterface
getDispatcher() deprecated

Get the event dispatcher.

Details

protected Language getLanguage() deprecated

Since: 5.3.0

deprecated 5.2 will be removed in 7.0 Plugin should use the language from Application, and only after the app is initialised.

Get the Language.

Return Value

Language

Exceptions

UnexpectedValueException

void setLanguage(Language $language) deprecated

Since: 5.3.0

deprecated 5.2 will be removed in 7.0 Plugin should use the language from Application, and only after the app is initialised

Set the language to use.

Parameters

Language $language

The language to use

Return Value

void

__construct(array $config = [])

Since: 1.5

Constructor

Parameters

array $config

An optional associative array of configuration settings. Recognized key values include 'name', 'group', 'params', 'language' (this list is not meant to be comprehensive).

bool loadLanguage(string $extension = '', string $basePath = JPATH_ADMINISTRATOR)

Since: 1.5

Loads the plugin language file

Parameters

string $extension

The extension for which a language file should be loaded

string $basePath

The basepath to use

Return Value

bool

True, if the file has successfully loaded.

void registerListeners()

Since: 4.0.0

Registers its listeners.

Return Value

void

final protected void registerLegacyListener(string $methodName)

Since: 4.0.0

Registers a legacy event listener, i.e. a method which accepts individual arguments instead of an AbstractEvent in its arguments. This provides backwards compatibility to Joomla! 3.x-style plugins.

This method will register lambda functions (closures) which try to unwrap the arguments of the dispatched Event into old style method arguments and call your on method with them. The result will be passed back to the Event, as an element into an array argument called 'result'.

Parameters

string $methodName

The method name to register

Return Value

void

final protected void registerListener(string $methodName)

Since: 4.0.0

Registers a proper event listener, i.e. a method which accepts an AbstractEvent as its sole argument. This is the preferred way to implement plugins in Joomla! 4.x and will be the only possible method with Joomla! 5.x onwards.

Parameters

string $methodName

The method name to register

Return Value

void

protected CMSApplicationInterface|null getApplication()

Since: 4.2.0

Returns the internal application or null when not set.

Return Value

CMSApplicationInterface|null

void setApplication(CMSApplicationInterface $application)

Since: 4.2.0

Sets the application to use.

Parameters

CMSApplicationInterface $application

The application

Return Value

void

$this setDispatcher(DispatcherInterface $dispatcher) deprecated

Since: 5.3.0

deprecated 5.2 will be removed in 7.0 Plugin should implement DispatcherAwareInterface on its own, when it is needed.

Set the dispatcher to use.

Parameters

DispatcherInterface $dispatcher

The dispatcher to use.

Return Value

$this

DispatcherInterface getDispatcher() deprecated

Since: 5.3.0

deprecated 5.2 will be removed in 7.0 Plugin should implement DispatcherAwareInterface on its own, when it is needed.

Get the event dispatcher.

Return Value

DispatcherInterface

Exceptions

UnexpectedValueException