Afform - Show breadcrumbs appropriate to whether a form can be edited
authorColeman Watts <coleman@civicrm.org>
Fri, 5 Mar 2021 15:32:42 +0000 (10:32 -0500)
committerColeman Watts <coleman@civicrm.org>
Sat, 6 Mar 2021 15:49:26 +0000 (10:49 -0500)
ext/afform/core/CRM/Afform/AfformScanner.php
ext/afform/core/CRM/Afform/Page/AfformBase.php
ext/afform/core/Civi/Api4/Action/Afform/Get.php

index d3b0f0770266bf368d5a8f83f092dcbee9a04fcf..e524a3f1f9146667d563aba7ded5c30c181822a1 100644 (file)
@@ -135,6 +135,7 @@ class CRM_Afform_AfformScanner {
       'is_dashlet' => FALSE,
       'is_public' => FALSE,
       'permission' => 'access CiviCRM',
+      'type' => 'system',
     ];
 
     $metaFile = $this->findFilePath($name, self::METADATA_FILE);
index fae234bcd0791039e895713b285b4951a02e63e6..ef78fec0b4b1084afb67d8d9103646e5496ca5e2 100644 (file)
@@ -9,9 +9,8 @@ class CRM_Afform_Page_AfformBase extends CRM_Core_Page {
 
     // The api will throw an exception if afform is not found (because of the index 0 param)
     $afform = civicrm_api4('Afform', 'get', [
-      'checkPermissions' => FALSE,
       'where' => [['name', '=', $pageArgs['afform']]],
-      'select' => ['title', 'module_name', 'directive_name'],
+      'select' => ['title', 'module_name', 'directive_name', 'type'],
     ], 0);
 
     $this->assign('directive', $afform['directive_name']);
@@ -20,24 +19,29 @@ class CRM_Afform_Page_AfformBase extends CRM_Core_Page {
       ->setModules([$afform['module_name'], 'afformStandalone'])
       ->load();
 
-    if (!empty($afform['title'])) {
-      $title = strip_tags($afform['title']);
-      CRM_Utils_System::setTitle($title);
-    }
-
     // If the user has "access civicrm" append home breadcrumb
     if (CRM_Core_Permission::check('access CiviCRM')) {
       CRM_Utils_System::appendBreadCrumb([['title' => ts('CiviCRM'), 'url' => CRM_Utils_System::url('civicrm')]]);
       // If the user has "admin civicrm" & the admin extension is enabled
-      if (CRM_Core_Permission::check('administer CiviCRM') && CRM_Utils_Array::findAll(
-          \CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles(),
-          ['fullName' => 'org.civicrm.afform_admin']
-        )) {
-        CRM_Utils_System::appendBreadCrumb([['title' => E::ts('Form Builder'), 'url' => CRM_Utils_System::url('civicrm/admin/afform')]]);
-        CRM_Utils_System::appendBreadCrumb([['title' => E::ts('Edit Form'), 'url' => CRM_Utils_System::url('civicrm/admin/afform', NULL, FALSE, '/edit/' . $pageArgs['afform'])]]);
+      if (CRM_Core_Permission::check('administer CiviCRM')) {
+        if (($pagePath[1] ?? NULL) === 'admin') {
+          CRM_Utils_System::appendBreadCrumb([['title' => E::ts('Admin'), 'url' => CRM_Utils_System::url('civicrm/admin')]]);
+        }
+        if ($afform['type'] !== 'system' &&
+          \CRM_Extension_System::singleton()->getMapper()->isActiveModule('afform_admin')
+        ) {
+          CRM_Utils_System::appendBreadCrumb([['title' => E::ts('Form Builder'), 'url' => CRM_Utils_System::url('civicrm/admin/afform')]]);
+          CRM_Utils_System::appendBreadCrumb([['title' => E::ts('Edit Form'), 'url' => CRM_Utils_System::url('civicrm/admin/afform', NULL, FALSE, '/edit/' . $pageArgs['afform'])]]);
+        }
       }
     }
 
+    if (!empty($afform['title'])) {
+      $title = strip_tags($afform['title']);
+      CRM_Utils_System::setTitle($title);
+      CRM_Utils_System::appendBreadCrumb([['title' => $title, 'url' => CRM_Utils_System::url(implode('/', $pagePath)) . '#']]);
+    }
+
     parent::run();
   }
 
index 00d86e39f1476e01740ecc2d3796f03c8a6e8058..58afed97ddc4b2a040983fed9b42d06ae956f44c 100644 (file)
@@ -54,6 +54,7 @@ class Get extends \Civi\Api4\Generic\BasicGetAction {
         $scanner->addComputedFields($values[$name]);
       }
       if ($getLayout) {
+        // Autogenerated layouts will already be in values but can be overridden; scanner takes priority
         $values[$name]['layout'] = $scanner->getLayout($name) ?? $values[$name]['layout'] ?? '';
       }
     }