4
0
Derivar 1

[DOCS] Expand developer Event documentation

Este cometimento está contido em:
Hugo Sales 2022-04-03 22:05:19 +01:00
ascendente d4b7e990ce
cometimento a2aa45fb1f
Assinados por: someonewithpc
ID da chave GPG: 7D0C7EAFC9D835A0
1 ficheiros modificados com 19 adições e 5 eliminações

Ver ficheiro

@ -45,10 +45,10 @@ Example 1: Adding elements to the core UI
* @param array $vars Input from the caller/emitter
* @param array $res I/O parameter used to accumulate or return values from the listener to the emitter
*
* @return bool true if not handled or if the handling should be accumulated with other listeners,
* @return \EventResult true if not handled or if the handling should be accumulated with other listeners,
* false if handled well enough and no other listeners are needed
*/
public function onViewAttachmentImage(array $vars, array &$res): bool
public function onViewAttachmentImage(array $vars, array &$res): \EventResult
{
$res[] = Formatting::twigRenderFile('imageEncoder/imageEncoderView.html.twig', ['attachment' => $vars['attachment'], 'thumbnail_parameters' => $vars['thumbnail_parameters']]);
return Event::stop;
@ -74,11 +74,25 @@ Event::handle('ResizerAvailable', [&$event_map]);
/**
* @param array $event_map output
*
* @return bool event hook
* @return \EventResult event hook
*/
public function onResizerAvailable(array &$event_map): bool
public function onResizerAvailable(array &$event_map): \EventResult
{
$event_map['image'] = 'ResizeImagePath';
return Event::next;
}
```
```
Example 3: Default action
-----
An event can be emited to perform an action, but still have a fallback as such:
> Event emitter
```php
if (Event::handle('EventName', $args) !== Event::stop): \EventResult
{
// Do default action, as no-one claimed authority on handling this event
}
```