Add a Saved Search in Your Own Extension¶
You can add a saved search that you created with Search Kit in your own extension. If you for example created a saved search like the Soft Credit Example and want to include it in your extension so there is an overview of soft credits and related contributions. You need 2 simple steps to accomplish this once you have created your search:
- export the search using the API4 Explorer with the SavedSearch entity
- save the exported search definition in the folder managed of your extension
Export your search¶
Once you have created your search you can export the saved search in 2 ways: from the overview of Saved Searches or directly in the API4 Explorer. I will detail using the Saved Search overview and explain how you can do this directly in the API4 Explorer afterwards.
Once you are on the list of saved searches you can click on the action menu behind each row and select the export option:
If you select this option you will get the option to save the search to the clipboard but also to package for distribution: using the API4 Explorer Export.
If you click on the link you will be presented with a prefilled API Explorer for your Saved Search: .
Now press the Execute button and copy the results array, then save this results array into the managed folder in your extension (using the copy button is a good idea). You'll also need to add
use CRM_Yourextension_ExtensionUtil as E; to the top of the file (not shown here).
If you now install your extension in a new environment your defined search will appear in the Saved Search list under the heading Packaged Searches. You'll need to ensure that you have the
mgd-php in your mixins in
info.xml for your Saved Search to show up, which you can do by running
civix mixin --enable=mgd-php@1.