HookStyleListener - Convey hook results. Refine type-hints.
authorTim Otten <totten@civicrm.org>
Mon, 31 May 2021 07:27:04 +0000 (00:27 -0700)
committerTim Otten <totten@civicrm.org>
Mon, 31 May 2021 07:31:47 +0000 (00:31 -0700)
Note: This is uncommon and discouraged for new hooks, but some hooks require returning values, e.g

```php
function hook_foo() {
  return ['my-data'];
}
```

This should fix compatibility with those.

Civi/Core/Event/HookStyleListener.php

index e901f30c8683bdccec32c1b6d59e0998a9a22cc1..28a3ee85a8d60cf165b8809487f8915cdf4362c6 100644 (file)
@@ -30,10 +30,11 @@ class HookStyleListener {
   }
 
   public function __invoke(GenericHookEvent $e) {
-    return call_user_func_array($this->callback, $e->getHookValues());
+    $result = call_user_func_array($this->callback, $e->getHookValues());
+    $e->addReturnValues($result);
   }
 
-  public function __toString() {
+  public function __toString(): string {
     $name = EventPrinter::formatName($this->callback);
     return preg_replace('/\(\$?e?\)$/', '(&...)', $name);
   }