mirror of
https://github.com/processwire/processwire.git
synced 2025-08-13 10:15:28 +02:00
Update HookEvent class to support named arguments directly from $event object
This commit is contained in:
@@ -119,8 +119,10 @@ class HookEvent extends WireData {
|
||||
*/
|
||||
public function argumentsByName($n = '') {
|
||||
|
||||
$names = $this->getArgumentNames();
|
||||
$arguments = $this->arguments();
|
||||
if(isset($arguments[$n])) return $arguments[$n];
|
||||
|
||||
$names = $this->getArgumentNames();
|
||||
|
||||
if($n) {
|
||||
$key = array_search($n, $names);
|
||||
@@ -222,6 +224,22 @@ class HookEvent extends WireData {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get
|
||||
*
|
||||
* @param object|string $key
|
||||
* @return mixed|null
|
||||
*
|
||||
*/
|
||||
public function get($key) {
|
||||
$value = parent::get($key);
|
||||
if($value === null && !ctype_digit("$key") && array_key_exists($key, $this->data['arguments'])) {
|
||||
// allow named arguments to be accessed from get()
|
||||
$value = $this->data['arguments'][$key];
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representing the HookEvent
|
||||
*
|
||||
|
Reference in New Issue
Block a user