1
0
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:
Ryan Cramer
2021-03-05 15:12:06 -05:00
parent 8718940b5d
commit 94e71209b3
3 changed files with 23 additions and 1 deletions

View File

@@ -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
*