From 236719c6919281c14235f5aa7f01bfa4ede315d7 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 5 Mar 2021 10:32:42 -0500 Subject: [PATCH] Afform - Show breadcrumbs appropriate to whether a form can be edited --- ext/afform/core/CRM/Afform/AfformScanner.php | 1 + .../core/CRM/Afform/Page/AfformBase.php | 30 +++++++++++-------- .../core/Civi/Api4/Action/Afform/Get.php | 1 + 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/ext/afform/core/CRM/Afform/AfformScanner.php b/ext/afform/core/CRM/Afform/AfformScanner.php index d3b0f07702..e524a3f1f9 100644 --- a/ext/afform/core/CRM/Afform/AfformScanner.php +++ b/ext/afform/core/CRM/Afform/AfformScanner.php @@ -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); diff --git a/ext/afform/core/CRM/Afform/Page/AfformBase.php b/ext/afform/core/CRM/Afform/Page/AfformBase.php index fae234bcd0..ef78fec0b4 100644 --- a/ext/afform/core/CRM/Afform/Page/AfformBase.php +++ b/ext/afform/core/CRM/Afform/Page/AfformBase.php @@ -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(); } diff --git a/ext/afform/core/Civi/Api4/Action/Afform/Get.php b/ext/afform/core/Civi/Api4/Action/Afform/Get.php index 00d86e39f1..58afed97dd 100644 --- a/ext/afform/core/Civi/Api4/Action/Afform/Get.php +++ b/ext/afform/core/Civi/Api4/Action/Afform/Get.php @@ -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'] ?? ''; } } -- 2.25.1