Since: 5.0.0

class BeforeSaveEvent extends AbstractSaveEvent implements ResultAwareInterface

Class for User save event.

Example: new BeforeSaveEvent('onEventName', ['subject' => $oldUserArray, 'isNew' => $isNew, 'data' => $data]);

Traits

This Trait partially implements the ResultAwareInterface for mutable and immutable events.

This Trait partially implements the ResultAwareInterface for type checking.

A Trait to reshape arguments maintaining b/c with legacy plugin events.

Returns the most suitable event class for a Joomla core event name

Properties

protected array deprecated Since: 5.0.0
$legacyArgumentsOrder

The argument names, in order expected by legacy plugins.

protected bool deprecated Since: 4.2.0
$preventSetArgumentResult

Disallow setting the result argument directly with setArgument() instead of going through addResult().

from  ResultAware
protected bool Since: 4.2.0
$resultIsNullable

Can the result attribute values also be NULL?

from  ResultTypeBooleanAware

Methods

static string
getEventClassByEventName(string $eventName)

Get the concrete event class name for the given event name.

static AbstractEvent
create(string $eventName, array $arguments = [])

Creates a new CMS event object for a given event name and subject. The following arguments must be given: subject object The subject of the event. This is the core object you are going to manipulate.

__construct(string $name, array $arguments = [])

Constructor.

mixed
getArgument(string $name, mixed $default = null)

Get an event argument value.

$this
setArgument(string $name, mixed $value)

Add argument to event.

void
offsetSet(string $name, mixed $value)

Set the value of an event argument.

void
offsetUnset(string $name)

Remove an event argument.

array
reshapeArguments(array $arguments, array $argumentNames, array $defaults = [])

Reshape the arguments array to preserve b/c with legacy listeners

array
onSetSubject(array $value)

Setter for the subject argument.

bool
onSetIsNew(bool $value)

Setter for the isNew argument.

array
getUser()

Getter for the user.

bool
getIsNew()

Getter for the isNew state.

void
addResult(mixed $data)

Appends data to the result array of the event.

array
setResult(array $value) deprecated

Handle setting the result argument directly.

array
onSetResult(array $value)

Handle setting the result argument directly.

void
typeCheckResult(mixed $data)

Checks the type of the data being appended to the result argument.

array
onSetData(array $value)

Setter for the data argument.

array
getData()

Getter for the data.

Details

static protected string getEventClassByEventName(string $eventName)

Since: 4.2.0

Get the concrete event class name for the given event name.

This method falls back to the generic Joomla\Event\Event class if the event name is unknown to this trait.

Parameters

string $eventName

The event name

Return Value

string

The event class name

static AbstractEvent create(string $eventName, array $arguments = [])

Since: 4.0.0

Creates a new CMS event object for a given event name and subject. The following arguments must be given: subject object The subject of the event. This is the core object you are going to manipulate.

eventClass string The Event class name. If you do not provide it Joomla\CMS\Events\ will be used.

Parameters

string $eventName

The name of the event, e.g. onTableBeforeLoad

array $arguments

Additional arguments to pass to the event

Return Value

AbstractEvent

Exceptions

BadMethodCallException

__construct(string $name, array $arguments = [])

Since: 5.0.0

Constructor.

Parameters

string $name

The event name.

array $arguments

The event arguments.

Exceptions

BadMethodCallException

mixed getArgument(string $name, mixed $default = null)

Since: 4.0.0

Get an event argument value.

It will use a pre-processing method if one exists. The method has the signature:

onGet($value): mixed

where:

$value is the value currently stored in the $arguments array of the event It returns the value to return to the caller.

Parameters

string $name

The argument name.

mixed $default

The default value if not found.

Return Value

mixed

The argument value or the default value.

$this setArgument(string $name, mixed $value)

Since: 4.0.0

Add argument to event.

It will use a pre-processing method if one exists. The method has the signature:

onSet($value): mixed

where:

$value is the value being set by the user It returns the value to return to set in the $arguments array of the event.

Parameters

string $name

Argument name.

mixed $value Value.

Return Value

$this

void offsetSet(string $name, mixed $value)

Since: 4.0.0

Set the value of an event argument.

Parameters

string $name

The argument name.

mixed $value

The argument value.

Return Value

void

Exceptions

BadMethodCallException

void offsetUnset(string $name)

Since: 4.0.0

Remove an event argument.

Parameters

string $name

The argument name.

Return Value

void

Exceptions

BadMethodCallException

protected array reshapeArguments(array $arguments, array $argumentNames, array $defaults = [])

Since: 4.2.0

Reshape the arguments array to preserve b/c with legacy listeners

Parameters

array $arguments

The named arguments array passed to the constructor.

array $argumentNames

The allowed argument names (mandatory AND optional).

array $defaults

Default values for optional arguments.

Return Value

array

The reshaped arguments.

protected array onSetSubject(array $value)

Since: 5.0.0

Setter for the subject argument.

Parameters

array $value

The value to set

Return Value

array

protected bool onSetIsNew(bool $value)

Since: 5.0.0

Setter for the isNew argument.

Parameters

bool $value

The value to set

Return Value

bool

array getUser()

Since: 5.0.0

Getter for the user.

Return Value

array

bool getIsNew()

Since: 5.0.0

Getter for the isNew state.

Return Value

bool

void addResult(mixed $data)

Since: 4.2.0

Appends data to the result array of the event.

Parameters

mixed $data

What to add to the result array.

Return Value

void

protected array setResult(array $value) deprecated

Since: 4.2.0

deprecated 4.4.0 will be removed in 6.0 Use counterpart with onSet prefix

Handle setting the result argument directly.

This method serves a dual purpose: backwards compatibility and enforcing the use of addResult.

When $this->preventSetArgumentResult is false it acts as a backwards compatibility shim for event handlers expecting generic event classes instead of the concrete Events implemented in this package. This allows the migration to concrete event classes throughout the lifetime of Joomla 4.x.

When $this->preventSetArgumentResult is false (which will always be the case on Joomla 5.0) it will throw a BadMethodCallException if the developer tries to call setArgument('result', ...) instead of going through the addResult() method.

Parameters

array $value

The new result array.

Return Value

array

protected array onSetResult(array $value)

Since: 4.4.0

Handle setting the result argument directly.

This method serves a dual purpose: backwards compatibility and enforcing the use of addResult.

When $this->preventSetArgumentResult is false it acts as a backwards compatibility shim for event handlers expecting generic event classes instead of the concrete Events implemented in this package. This allows the migration to concrete event classes throughout the lifetime of Joomla 4.x.

When $this->preventSetArgumentResult is false (which will always be the case on Joomla 5.0) it will throw a BadMethodCallException if the developer tries to call setArgument('result', ...) instead of going through the addResult() method.

Parameters

array $value

The new result array.

Return Value

array

void typeCheckResult(mixed $data)

Since: 4.2.0
internal  
 

Checks the type of the data being appended to the result argument.

Parameters

mixed $data

The data to type check

Return Value

void

Exceptions

InvalidArgumentException

protected array onSetData(array $value)

Since: 5.0.0

Setter for the data argument.

Parameters

array $value

The value to set

Return Value

array

array getData()

Since: 5.0.0

Getter for the data.

Return Value

array