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

SearchKit - Rename crmSearchActions module to crmSearchTasks & add hook #20307

Merged
merged 1 commit into from
May 19, 2021

Conversation

colemanw
Copy link
Member

Overview

Adds hook_civicrm_searchKitTasks() to make it easy for other extensions to add tasks specific to SearchKit.
Also renames the module for consistency.

Before

No hook, difficult for other extensions to add tasks.

After

Extensions can add tasks.

Technical Details

The tasks added by the extension can contain a module key which will trigger it to be auto-loaded as a dependency of the crmSearchTasks module.

@civibot
Copy link

civibot bot commented May 14, 2021

(Standard links)

@colemanw
Copy link
Member Author

@eileenmcnaughton this diff looks daunting but it's just because I renamed the module. The word "actions" is ambiguous and in core they're called "tasks".

@eileenmcnaughton
Copy link
Contributor

OK I tested this & it works - yay. Changes are noisy due to name change, as you say

@eileenmcnaughton eileenmcnaughton merged commit 9974fc5 into civicrm:master May 19, 2021
@eileenmcnaughton eileenmcnaughton deleted the searchTaskHook branch May 19, 2021 00:19
@eileenmcnaughton
Copy link
Contributor

@aydun
Copy link
Contributor

aydun commented Jun 1, 2021

@colemanw I know this is already merged but looking at the rest of GetSearchTasks::_run() it would seem that $entity, or at least $entity['name'] and $entity['actions'] could be useful in implementations of hook_civicrm_searchKitTasks when deciding what tasks to add. Do you agree?

@colemanw
Copy link
Member Author

colemanw commented Jun 1, 2021

@aydun if you inspect the $tasks variable being passed to the hook it looks like:

$tasks = [
  'Contact' => [[...], [...], etc],
  'Participant' => [[...], etc],
];

so the idea is that hook subscribers can just add items to the array key of the entity they want. And PHP (which can be a PITA about undefined variables compared to the more lackadaisical javascript) actually works without complaining even if the key doesn't exist yet. So given the above array your hook could do $tasks['FooBar'][] = [...] and it will add the entity and the task to the array.

@colemanw
Copy link
Member Author

colemanw commented Jun 2, 2021

Added some code comments in #20467

@aydun
Copy link
Contributor

aydun commented Jun 2, 2021

@colemanw Ah ok - those code comments are helpful. I was looking at the conditionals in _run(): if contacts, add contact tasks; if contributions, add contribution tasks - and thinking hook implementations might want to do the same. But I get your point about Angular dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants