Fundraising/Internal-facing/CiviCRM/Exporting SearchKit Search into an extension
Appearance
This is necessary, if the extension is designed to be reused and the search is an integral aspect of the usability of the form. The following steps would describe how to ensure a SearchKit search is packaged into a custom extension.
- On the top left Navigation bar, select Search and in the dropdown, click on SearchKit.
- In the custom searches, filter the list by entering the name of the search created in the steps above.
- On the row that corresponds to the target search, select the hamburger menu on the extreme right and click on Export.
- In the popup dialog, click on the API Explorer Export link in the highlighted text. This would cause the page to navigate to the CiviCRM APIv4 page preconfigured to the export query on the SavedSearch entity.
- Click on the Execute button to initiate the query.
- In the Result tab at the bottom of the page, set the result formatter to "View as PHP" as the next step would be dependent on that.
- Click on the "Copy" button to copy the entire result.
- On the extension directory in the file system, create a new directory titled "managed"
- In this "managed" directory create a new php file with title {desired_name}.mgd.php where the variable desired_name could be any name you choose. The most important aspect of this is the file extension that is ".mgd.php".
- In this new file, initiate the php script with the php opening tag "<?php"
- Then paste in the php code copied from the API Explorer Export results in step 7.
- Save the file and now the SearchKit search is re-usable anywhere the extension is installed.
- Whenever the extension is installed, the SearchKit search would be found in the "Packaged Searches" tab