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

NEW Simplify the verification of context in hook #27105

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Changes from 1 commit
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
Next Next commit
NEW Simplify the verification of context in hook
  • Loading branch information
d3v2a committed Dec 14, 2023
commit 91f1c2d4fb324c75a952db24147c7a844a8107d3
22 changes: 22 additions & 0 deletions htdocs/core/class/commonhookactions.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,26 @@ abstract class CommonHookActions
* @var array Array of results.
*/
public $results = array();

/**
* Check context of hook
* @param array $parameters Hook parameters.
* @param array|string $allContexts Context to check
* @return bool
*/
protected function isContext($parameters, $allContexts)
{
if (is_array($allContexts)) {
foreach ($allContexts as $context) {
if ($this->isContext($parameters, $context)) {
return true;
}
}
}
if ($parameters['currentcontext'] == $allContexts) {
return true;
}
$contexts = explode(':', $parameters['context']);
return in_array($allContexts, $contexts);
}
}