Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM_Utils_Hook: deprecation warning and short array syntax #17995

Merged
merged 1 commit into from
Aug 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions CRM/Utils/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ abstract public function invokeViaUF(
* but also accepts enough information to support Symfony Event
* dispatching.
*
* @param array|int $names
* @param array $names
* (Recommended) Array of parameter names, in order.
* Using an array is recommended because it enables full
* event-broadcasting behaviors.
Expand All @@ -155,15 +155,14 @@ public function invoke(
if (!is_array($names)) {
// We were called with the old contract wherein $names is actually an int.
// Symfony dispatcher requires some kind of name.
// TODO: Emit a warning, eg
// error_log("Warning: hook_$fnSuffix does not give names for its parameters. It will present odd names to any Symfony event listeners.");
Civi::log()->warning("hook_$fnSuffix should be updated to pass an array of parameter names to CRM_Utils_Hook::invoke().", ['civi.tag' => 'deprecated']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@colemanw the CRM_Core_Error::deprecatedFunctionWarning( wrapper function might not be perfect - but it's more greppable so I think it's preferred

$compatNames = ['arg1', 'arg2', 'arg3', 'arg4', 'arg5', 'arg6'];
$names = array_slice($compatNames, 0, (int) $names);
}

$event = \Civi\Core\Event\GenericHookEvent::createOrdered(
$names,
array(&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6)
[&$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6]
);
\Civi::dispatcher()->dispatch('hook_' . $fnSuffix, $event);
return $event->getReturnValues();
Expand Down Expand Up @@ -678,7 +677,7 @@ public static function themes(&$themes) {
* the return value is ignored
*/
public static function activeTheme(&$theme, $context) {
return self::singleton()->invoke(array('theme', 'context'), $theme, $context,
return self::singleton()->invoke(['theme', 'context'], $theme, $context,
self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
'civicrm_activeTheme'
);
Expand Down Expand Up @@ -869,7 +868,7 @@ public static function tokens(&$tokens) {
* @return mixed
*/
public static function alterAdminPanel(&$panels) {
return self::singleton()->invoke(array('panels'), $panels,
return self::singleton()->invoke(['panels'], $panels,
self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
'civicrm_alterAdminPanel'
);
Expand Down