Fundraising/Internal-facing/CiviCRM/Exporting SearchKit Search into an extension

From Wikitech

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.

  1. On the top left Navigation bar, select Search and in the dropdown, click on SearchKit.
  2. In the custom searches, filter the list by entering the name of the search created in the steps above.
  3. On the row that corresponds to the target search, select the hamburger menu on the extreme right and click on Export.
  4. 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.
  5. Click on the Execute button to initiate the query.
  6. 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.
  7. Click on the "Copy" button to copy the entire result.
  8. On the extension directory in the file system, create a new directory titled "managed"
  9. 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".
  10. In this new file, initiate the php script with the php opening tag "<?php"
  11. Then paste in the php code copied from the API Explorer Export results in step 7.
  12. Save the file and now the SearchKit search is re-usable anywhere the extension is installed.
  13. Whenever the extension is installed, the SearchKit search would be found in the "Packaged Searches" tab
Related Topics: