diff --git a/ext/afform/core/Civi/Api4/Action/CustomGroup/GetAfforms.php b/ext/afform/core/Civi/Api4/Action/CustomGroup/GetAfforms.php index 7f7f9dc6f25..9cd1d5a0950 100644 --- a/ext/afform/core/Civi/Api4/Action/CustomGroup/GetAfforms.php +++ b/ext/afform/core/Civi/Api4/Action/CustomGroup/GetAfforms.php @@ -26,6 +26,7 @@ class GetAfforms extends \Civi\Api4\Generic\BasicBatchAction { 'afblockCustom', 'afformUpdateCustom', 'afformCreateCustom', + 'afformViewCustom', 'afsearchTabCustom', ]; @@ -74,6 +75,7 @@ protected function doTask($item) { break; case 'form': + $forms[] = $this->generateViewForm($item); $forms[] = $this->generateUpdateForm($item); if ($item['is_multiple']) { $forms[] = $this->generateCreateForm($item); @@ -123,6 +125,56 @@ private function generateFieldBlock($item): array { return $afform; } + private function generateViewForm($item): array { + $afform = [ + 'name' => 'afformViewCustom_' . $item['name'], + 'type' => 'form', + 'title' => E::ts('View %1', [1 => $item['title']]), + 'description' => '', + 'is_public' => FALSE, + // NOTE: we will use RBAC for entities to ensure + // this form does not allow folks who shouldn't + // to edit contacts + 'permission' => ['access CiviCRM'], + 'server_route' => 'civicrm/af/custom/' . $item['name'] . '/view', + 'icon' => $item['icon'], + ]; + if ($this->getLayout) { + + // form entity depends on whether this is a multirecord custom group + $formEntity = $item['is_multiple'] ? + [ + 'type' => 'Custom_' . $item['name'], + 'name' => 'Record', + 'label' => $item['extends'] . ' ' . $item['title'], + 'parent_field' => 'entity_id', + 'parent_field_defn' => [ + 'input_type' => 'Hidden', + 'label' => FALSE, + ], + ] : + [ + 'type' => $item['extends'], + 'name' => $item['extends'] . '1', + 'label' => $item['extends'], + 'parent_field' => 'id', + 'parent_field_defn' => [ + 'input_type' => 'Hidden', + 'label' => FALSE, + ], + ]; + + $afform['layout'] = \CRM_Core_Smarty::singleton()->fetchWith( + 'afform/customGroups/afformView.tpl', + [ + 'formEntity' => $formEntity, + 'group' => $item, + ] + ); + } + return $afform; + } + private function generateUpdateForm($item): array { $afform = [ 'name' => 'afformUpdateCustom_' . $item['name'], @@ -163,7 +215,7 @@ private function generateUpdateForm($item): array { ]; $afform['layout'] = \CRM_Core_Smarty::singleton()->fetchWith( - 'afform/customGroups/afform.tpl', + 'afform/customGroups/afformEdit.tpl', [ 'formEntity' => $formEntity, 'formActions' => [ @@ -204,7 +256,7 @@ private function generateCreateForm($item): array { ], ]; $afform['layout'] = \CRM_Core_Smarty::singleton()->fetchWith( - 'afform/customGroups/afform.tpl', + 'afform/customGroups/afformEdit.tpl', [ 'formEntity' => $formEntity, 'formActions' => [ diff --git a/ext/afform/core/templates/afform/customGroups/afform.tpl b/ext/afform/core/templates/afform/customGroups/afformEdit.tpl similarity index 100% rename from ext/afform/core/templates/afform/customGroups/afform.tpl rename to ext/afform/core/templates/afform/customGroups/afformEdit.tpl diff --git a/ext/afform/core/templates/afform/customGroups/afformView.tpl b/ext/afform/core/templates/afform/customGroups/afformView.tpl new file mode 100644 index 00000000000..783dbd22e04 --- /dev/null +++ b/ext/afform/core/templates/afform/customGroups/afformView.tpl @@ -0,0 +1,22 @@ + + + +
+ + {foreach from=$group.field_names item=field_name} + {* for multiple record fields there is no need to prepend + the group name because it will be the form entity itself *} + + {/foreach} +
+
diff --git a/ext/civicrm_admin_ui/Civi/Api4/Event/Subscriber/CustomGroupEntityLinks.php b/ext/civicrm_admin_ui/Civi/Api4/Event/Subscriber/CustomGroupEntityLinks.php index 246ce6e8712..704cd4762fe 100644 --- a/ext/civicrm_admin_ui/Civi/Api4/Event/Subscriber/CustomGroupEntityLinks.php +++ b/ext/civicrm_admin_ui/Civi/Api4/Event/Subscriber/CustomGroupEntityLinks.php @@ -34,6 +34,7 @@ public function addCustomGroupLinks(\Civi\Core\Event\GenericHookEvent $event) { $groupName = substr($name, 7); $event->entities[$name]['paths']['add'] = "civicrm/af/custom/{$groupName}/create#?entity_id=[entity_id]"; $event->entities[$name]['paths']['update'] = "civicrm/af/custom/{$groupName}/update#?Record=[id]"; + $event->entities[$name]['paths']['view'] = "civicrm/af/custom/{$groupName}/view#?Record=[id]"; } } }