Lifecycle hook methods
Magewire knows several lifecycle hook methods which can be optionally implemented by a components as needed.
Each hook method has a specific name. If a hook method exists on a component class, Magewire will automatically call it at the appropriate time.
Lifecycle hook method table
Keeping in mind the different phases during a component's lifecycle, we can choose which method to use for any given scenario.
|lifecycle hook method||called during preceding requests?||called during subsequent requests?||component hydrated?||properties updated?|
In summary, during the preceding request, the available hook methods are:
During subsequent requests, the available hook methods are:
Note about Full Page Caching
For components on cached pages, no lifecycle hook methods will be called during the
preceeding request, if the page is served from cache!
Only when a page is not in the cache, that is, when the component is rendered the first time, hook methods are called during the
It is different for subsequent requests.
Subsequent requests are never served from the full-page cache.
They always bypass the full-page cache and are processed by Magento, because they are Ajax requests.
Thus all lifecycle hook methods are called during
Property specific hook methods
Each property receiving a new value during a subsequent request will cause a matching
updating*() method to be called, before the new value is set, and an
updated*() method to be called after the new value is set.
For example, if a method name like
updateFoo is used,
Foo stands for the property name
The full list of property specific lifecycle hook methods:
This also works for camelCase properties:
And it even works with snake_case properties, even though are against any coding standard in the Magento context. The hook method names for snake_case properties use camelCase, too.
It is also possible to define callback methods targeting nested array properties.
Please refer to the page Working with Arrays for more information.
Lifecycle hook method arguments
There are several rules and conventions around hook method arguments:
If a hook method receives a
$valueargument, it must return it from the hook method, too.
$blockDataargument some hook methods receive is the array returned by
If a hook methods receives a
$requestargument, it will be an instance of
When a hook method receives a
$responseargument, it will be an instance of