From 7f3c8b3de1eef88b942ab3e60cbbcd08d4b1c3d8 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 16 Nov 2018 11:44:39 +1300 Subject: [PATCH] Partial converstion of Profile form to be an entity form, fixes translatability for frontend title --- CRM/Core/DAO/UFGroup.php | 12 +++++-- CRM/UF/Form/Group.php | 60 ++++++++++++++++++++++++++------- templates/CRM/UF/Form/Group.tpl | 16 +++------ xml/schema/Core/UFGroup.xml | 8 +++++ 4 files changed, 70 insertions(+), 26 deletions(-) diff --git a/CRM/Core/DAO/UFGroup.php b/CRM/Core/DAO/UFGroup.php index 1480a27e7b..4667ad2c48 100644 --- a/CRM/Core/DAO/UFGroup.php +++ b/CRM/Core/DAO/UFGroup.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Core/UFGroup.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:a48f9522d0bd2e1d485064ebfc66f9a2) + * (GenCodeChecksum:d0a806459507dc6b32ba955e4e899358) */ /** @@ -291,7 +291,7 @@ class CRM_Core_DAO_UFGroup extends CRM_Core_DAO { 'title' => [ 'name' => 'title', 'type' => CRM_Utils_Type::T_STRING, - 'title' => ts('Title'), + 'title' => ts('Profile Name'), 'description' => ts('Form title.'), 'required' => TRUE, 'maxlength' => 64, @@ -300,11 +300,14 @@ class CRM_Core_DAO_UFGroup extends CRM_Core_DAO { 'entity' => 'UFGroup', 'bao' => 'CRM_Core_BAO_UFGroup', 'localizable' => 1, + 'html' => [ + 'type' => 'Text', + ], ], 'frontend_title' => [ 'name' => 'frontend_title', 'type' => CRM_Utils_Type::T_STRING, - 'title' => ts('Frontend Title'), + 'title' => ts('Public Title'), 'description' => ts('Profile Form Public title'), 'maxlength' => 64, 'size' => CRM_Utils_Type::BIG, @@ -312,6 +315,9 @@ class CRM_Core_DAO_UFGroup extends CRM_Core_DAO { 'entity' => 'UFGroup', 'bao' => 'CRM_Core_BAO_UFGroup', 'localizable' => 1, + 'html' => [ + 'type' => 'Text', + ], ], 'description' => [ 'name' => 'description', diff --git a/CRM/UF/Form/Group.php b/CRM/UF/Form/Group.php index 9fcb834176..933cfc537f 100644 --- a/CRM/UF/Form/Group.php +++ b/CRM/UF/Form/Group.php @@ -29,15 +29,51 @@ * * @package CRM * @copyright CiviCRM LLC (c) 2004-2018 - * $Id$ - * */ /** - * This class is for UF Group + * This class is for UF Group (Profile) configuration. */ class CRM_UF_Form_Group extends CRM_Core_Form { + use CRM_Core_Form_EntityFormTrait; + + /** + * Fields for the entity to be assigned to the template. + * + * Fields may have keys + * - name (required to show in tpl from the array) + * - description (optional, will appear below the field) + * - not-auto-addable - this class will not attempt to add the field using addField. + * (this will be automatically set if the field does not have html in it's metadata + * or is not a core field on the form's entity). + * - help (option) add help to the field - e.g ['id' => 'id-source', 'file' => 'CRM/Contact/Form/Contact']] + * - template - use a field specific template to render this field + * - required + * - is_freeze (field should be frozen). + * + * @var array + */ + protected $entityFields = []; + + /** + * Set entity fields to be assigned to the form. + */ + protected function setEntityFields() { + $this->entityFields = [ + 'title' => ['name' => 'title'], + 'frontend_title' => ['name' => 'frontend_title'], + 'description' => ['name' => 'description', 'help' => ['id' => 'id-description', 'file' => 'CRM/UF/Form/Group.hlp']], + ]; + } + + /** + * Explicitly declare the entity api name. + */ + public function getDefaultEntity() { + return 'UFGroup'; + } + /** * The form id saved to the session for an update. * @@ -57,8 +93,6 @@ class CRM_UF_Form_Group extends CRM_Core_Form { /** * Set variables up before form is built. - * - * @return void */ public function preProcess() { // current form id @@ -111,6 +145,7 @@ class CRM_UF_Form_Group extends CRM_Core_Form { * @return void */ public function buildQuickForm() { + self::buildQuickEntityForm(); if ($this->_action & (CRM_Core_Action::DISABLE | CRM_Core_Action::DELETE)) { if ($this->_action & (CRM_Core_Action::DISABLE)) { $display = 'Disable Profile'; @@ -132,12 +167,6 @@ class CRM_UF_Form_Group extends CRM_Core_Form { )); return; } - $this->applyFilter('__ALL__', 'trim'); - - // title - $this->add('text', 'title', ts('Profile Name'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'title'), TRUE); - $this->add('text', 'frontend_title', ts('Public Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'frontend_title')); - $this->add('textarea', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'description')); //add checkboxes $uf_group_type = array(); @@ -335,7 +364,7 @@ class CRM_UF_Form_Group extends CRM_Core_Form { } else { // get the submitted form values. - $params = $ids = array(); + $ids = array(); $params = $this->controller->exportValues($this->_name); if (!array_key_exists('is_active', $params)) { @@ -386,4 +415,11 @@ class CRM_UF_Form_Group extends CRM_Core_Form { CRM_Utils_System::updateCategories(); } + /** + * Set the delete message. + * + * We do this from the constructor in order to do a translation. + */ + public function setDeleteMessage() {} + } diff --git a/templates/CRM/UF/Form/Group.tpl b/templates/CRM/UF/Form/Group.tpl index 5af929ddc6..6e86a4e8b2 100644 --- a/templates/CRM/UF/Form/Group.tpl +++ b/templates/CRM/UF/Form/Group.tpl @@ -46,18 +46,12 @@ {else} - - - - - - - - - - - + {foreach from=$entityFields item=fieldSpec} + {assign var=fieldName value=$fieldSpec.name} + + {include file="CRM/Core/Form/Field.tpl"} + {/foreach} diff --git a/xml/schema/Core/UFGroup.xml b/xml/schema/Core/UFGroup.xml index 6339d9c6cf..350273655b 100644 --- a/xml/schema/Core/UFGroup.xml +++ b/xml/schema/Core/UFGroup.xml @@ -46,19 +46,27 @@ title + Profile Name varchar 64 true true + + Text + Form title. 1.1 frontend_title + Public Title varchar 64 true Profile Form Public title + + Text + 4.7 -- 2.25.1
{$form.title.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_uf_group' field='title' id=$gid}{/if}{$form.title.html}
{$form.frontend_title.label}{$form.frontend_title.html}
{$form.description.label} {help id='id-description' file="CRM/UF/Form/Group.hlp"}{$form.description.html}
{$form.uf_group_type.label} {help id='id-used_for' file="CRM/UF/Form/Group.hlp"} {$form.uf_group_type.html} {$otherModuleString}