From 7da21f11e4d5601341a5804baba370ee1bb432fb Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 25 Mar 2019 22:21:39 +1300 Subject: [PATCH] Partial converstion of Group form to be an EntityForm This is mostly for demo purposes and it should be noted that these changes are generally done in a 'step in the right direction' kinda way, and in accordance with this I have made a very minimal change. In this case the change gets the form to be using the entity form and converts two field. The change didn't initially work for the title field because the schema didn't define the html type for the field - fixing these things is a feature not a bug of switching to an entity form We can remove the apply filter line & the addButtons fn as the parent does these (actually it adds the custom data too but I've left that out of scope). If we converted a few more fields we would see that 1) the saved_search_id doesn't have a pseudoconstant defined in the schema, as it should 2) the various field description & help info is not in the schema 3) when we convert the tpl file we add custom data support in, although this form already has it When we finally switch to a non-quickform layer the new forms will be built of the schema so by transferring information into the schema and out of thousands of differently coded forms we take steps in the direction of facilitating that. That perhaps seems a little unachievable but the api was originally as incoherent as the form layer and it was only by incremental cleanup it became more consisten --- CRM/Contact/DAO/Group.php | 5 ++- CRM/Group/Form/Edit.php | 66 ++++++++++++++++++------------------ xml/schema/Contact/Group.xml | 3 ++ 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/CRM/Contact/DAO/Group.php b/CRM/Contact/DAO/Group.php index 1174320105..71b28d3367 100644 --- a/CRM/Contact/DAO/Group.php +++ b/CRM/Contact/DAO/Group.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Contact/Group.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:48373e283a62b36aa59ac812f8cb4134) + * (GenCodeChecksum:21b3e21494b0831994f860083cd82e24) */ /** @@ -236,6 +236,9 @@ class CRM_Contact_DAO_Group extends CRM_Core_DAO { 'entity' => 'Group', 'bao' => 'CRM_Contact_BAO_Group', 'localizable' => 1, + 'html' => [ + 'type' => 'Text', + ], ], 'description' => [ 'name' => 'description', diff --git a/CRM/Group/Form/Edit.php b/CRM/Group/Form/Edit.php index 789689886f..3c3e9722fb 100644 --- a/CRM/Group/Form/Edit.php +++ b/CRM/Group/Form/Edit.php @@ -36,6 +36,8 @@ */ class CRM_Group_Form_Edit extends CRM_Core_Form { + use CRM_Core_Form_EntityFormTrait; + /** * The group id, used when editing a group * @@ -78,6 +80,35 @@ class CRM_Group_Form_Edit extends CRM_Core_Form { */ protected $_groupOrganizationID; + /** + * Set entity fields to be assigned to the form. + */ + protected function setEntityFields() { + $this->entityFields = [ + 'title' => [ + 'name' => 'title', + 'required' => TRUE, + ], + 'description' => ['name' => 'description'], + ]; + } + + /** + * Set the delete message. + * + * We do this from the constructor in order to do a translation. + */ + public function setDeleteMessage() { + $this->deleteMessage = ''; + } + + /** + * Explicitly declare the entity api name. + */ + public function getDefaultEntity() { + return 'Group'; + } + /** * Set up variables to build the form. */ @@ -213,18 +244,8 @@ class CRM_Group_Form_Edit extends CRM_Core_Form { * Build the form object. */ public function buildQuickForm() { - if ($this->_action == CRM_Core_Action::DELETE) { - $this->addButtons(array( - array( - 'type' => 'next', - 'name' => ts('Delete Group'), - 'isDefault' => TRUE, - ), - array( - 'type' => 'cancel', - 'name' => ts('Cancel'), - ), - )); + self::buildQuickEntityForm(); + if ($this->_action & CRM_Core_Action::DELETE) { return; } @@ -233,15 +254,6 @@ class CRM_Group_Form_Edit extends CRM_Core_Form { $this->preventAjaxSubmit(); } - $this->applyFilter('__ALL__', 'trim'); - $this->add('text', 'title', ts('Name') . ' ', - CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title'), TRUE - ); - - $this->add('textarea', 'description', ts('Description') . ' ', - CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'description') - ); - $groupTypes = CRM_Core_OptionGroup::values('group_type', TRUE); if (isset($this->_id) && !empty($this->_groupValues['saved_search_id'])) { @@ -272,18 +284,6 @@ class CRM_Group_Form_Edit extends CRM_Core_Form { //build custom data CRM_Custom_Form_CustomData::buildQuickForm($this); - $this->addButtons(array( - array( - 'type' => 'upload', - 'name' => ($this->_action == CRM_Core_Action::ADD) ? ts('Continue') : ts('Save'), - 'isDefault' => TRUE, - ), - array( - 'type' => 'cancel', - 'name' => ts('Cancel'), - ), - )); - $doParentCheck = FALSE; if (CRM_Core_Permission::isMultisiteEnabled()) { $doParentCheck = ($this->_id && CRM_Core_BAO_Domain::isDomainGroup($this->_id)) ? FALSE : TRUE; diff --git a/xml/schema/Contact/Group.xml b/xml/schema/Contact/Group.xml index 4deea9bf96..330e1a42db 100644 --- a/xml/schema/Contact/Group.xml +++ b/xml/schema/Contact/Group.xml @@ -35,6 +35,9 @@ true Name of Group. 1.1 + + Text + description -- 2.25.1