Merge pull request #19758 from colemanw/searchKitFix
[civicrm-core.git] / ext / afform / core / CRM / Afform / Page / AfformBase.php
1 <?php
2 use CRM_Afform_ExtensionUtil as E;
3
4 class CRM_Afform_Page_AfformBase extends CRM_Core_Page {
5
6 public function run() {
7 // To avoid php complaints about the number of args passed to this function vs the base function
8 [$pagePath, $pageArgs] = func_get_args();
9
10 // The api will throw an exception if afform is not found (because of the index 0 param)
11 $afform = civicrm_api4('Afform', 'get', [
12 'where' => [['name', '=', $pageArgs['afform']]],
13 'select' => ['title', 'module_name', 'directive_name', 'type'],
14 ], 0);
15
16 $this->assign('directive', $afform['directive_name']);
17
18 (new \Civi\Angular\AngularLoader())
19 ->setModules([$afform['module_name'], 'afformStandalone'])
20 ->load();
21
22 // If the user has "access civicrm" append home breadcrumb
23 if (CRM_Core_Permission::check('access CiviCRM')) {
24 CRM_Utils_System::appendBreadCrumb([['title' => ts('CiviCRM'), 'url' => CRM_Utils_System::url('civicrm')]]);
25 // If the user has "admin civicrm" & the admin extension is enabled
26 if (CRM_Core_Permission::check('administer CiviCRM')) {
27 if (($pagePath[1] ?? NULL) === 'admin') {
28 CRM_Utils_System::appendBreadCrumb([['title' => E::ts('Admin'), 'url' => CRM_Utils_System::url('civicrm/admin')]]);
29 }
30 if ($afform['type'] !== 'system' &&
31 \CRM_Extension_System::singleton()->getMapper()->isActiveModule('afform_admin')
32 ) {
33 CRM_Utils_System::appendBreadCrumb([['title' => E::ts('Form Builder'), 'url' => CRM_Utils_System::url('civicrm/admin/afform')]]);
34 CRM_Utils_System::appendBreadCrumb([['title' => E::ts('Edit Form'), 'url' => CRM_Utils_System::url('civicrm/admin/afform', NULL, FALSE, '/edit/' . $pageArgs['afform'])]]);
35 }
36 }
37 }
38
39 if (!empty($afform['title'])) {
40 $title = strip_tags($afform['title']);
41 CRM_Utils_System::setTitle($title);
42 CRM_Utils_System::appendBreadCrumb([['title' => $title, 'url' => CRM_Utils_System::url(implode('/', $pagePath)) . '#']]);
43 }
44
45 parent::run();
46 }
47
48 }