From 80a9650814f058166543af3a90f6e886f85b11f6 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 15 May 2018 14:14:50 +1200 Subject: [PATCH] Add labels to membership type metadata, allowing for addField method to be used --- CRM/Core/CodeGen/Specification.php | 1 + CRM/Core/Form.php | 3 ++- CRM/Core/I18n/SchemaStructure.php | 2 ++ CRM/Member/DAO/MembershipType.php | 7 ++++++- CRM/Member/Form/MembershipType.php | 31 ++++++++-------------------- xml/schema/Member/MembershipType.xml | 5 +++++ 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/CRM/Core/CodeGen/Specification.php b/CRM/Core/CodeGen/Specification.php index 5d06369437..554f3fa27b 100644 --- a/CRM/Core/CodeGen/Specification.php +++ b/CRM/Core/CodeGen/Specification.php @@ -371,6 +371,7 @@ class CRM_Core_CodeGen_Specification { $validOptions = array( 'type', 'formatType', + 'label', /* Fixme: prior to CRM-13497 these were in a flat structure // CRM-13497 moved them to be nested within 'html' but there's no point // making that change in the DAOs right now since we are in the process of diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 58c332f48b..0d8286fd15 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1413,7 +1413,8 @@ class CRM_Core_Form extends HTML_QuickForm_Page { // Core field - get metadata. $fieldSpec = civicrm_api3($props['entity'], 'getfield', $props); $fieldSpec = $fieldSpec['values']; - $label = CRM_Utils_Array::value('label', $props, isset($fieldSpec['title']) ? $fieldSpec['title'] : NULL); + $fieldSpecLabel = isset($fieldSpec['html']['label']) ? $fieldSpec['html']['label'] : CRM_Utils_Array::value('title', $fieldSpec); + $label = CRM_Utils_Array::value('label', $props, $fieldSpecLabel); $widget = isset($props['type']) ? $props['type'] : $fieldSpec['html']['type']; if ($widget == 'TextArea' && $context == 'search') { diff --git a/CRM/Core/I18n/SchemaStructure.php b/CRM/Core/I18n/SchemaStructure.php index 6e06171f2f..2c7f442856 100755 --- a/CRM/Core/I18n/SchemaStructure.php +++ b/CRM/Core/I18n/SchemaStructure.php @@ -489,11 +489,13 @@ class CRM_Core_I18n_SchemaStructure { 'civicrm_membership_type' => [ 'name' => [ 'type' => "Text", + 'label' => "Name", ], 'description' => [ 'type' => "TextArea", 'rows' => "6", 'cols' => "50", + 'label' => "Description", ], ], 'civicrm_membership_block' => [ diff --git a/CRM/Member/DAO/MembershipType.php b/CRM/Member/DAO/MembershipType.php index e80dfadc60..f47bc47760 100644 --- a/CRM/Member/DAO/MembershipType.php +++ b/CRM/Member/DAO/MembershipType.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Member/MembershipType.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:f79b8b7075dd740416b24eff8ebd147b) + * (GenCodeChecksum:51b478b01b1ef20a54b1039ccc29d0ab) */ /** @@ -248,6 +248,7 @@ class CRM_Member_DAO_MembershipType extends CRM_Core_DAO { 'localizable' => 1, 'html' => [ 'type' => 'Text', + 'label' => 'Name', ], ], 'description' => [ @@ -263,6 +264,7 @@ class CRM_Member_DAO_MembershipType extends CRM_Core_DAO { 'localizable' => 1, 'html' => [ 'type' => 'TextArea', + 'label' => 'Description', ], ], 'member_of_contact_id' => [ @@ -309,6 +311,7 @@ class CRM_Member_DAO_MembershipType extends CRM_Core_DAO { 'localizable' => 0, 'html' => [ 'type' => 'Text', + 'label' => 'Minimum Fee', ], ], 'duration_unit' => [ @@ -414,6 +417,7 @@ class CRM_Member_DAO_MembershipType extends CRM_Core_DAO { 'localizable' => 0, 'html' => [ 'type' => 'Text', + 'label' => 'Max Related', ], ], 'visibility' => [ @@ -500,6 +504,7 @@ class CRM_Member_DAO_MembershipType extends CRM_Core_DAO { 'localizable' => 0, 'html' => [ 'type' => 'CheckBox', + 'label' => 'Enabled?', ], ], ]; diff --git a/CRM/Member/Form/MembershipType.php b/CRM/Member/Form/MembershipType.php index a39e17508f..ba2ab9c19a 100644 --- a/CRM/Member/Form/MembershipType.php +++ b/CRM/Member/Form/MembershipType.php @@ -134,24 +134,20 @@ class CRM_Member_Form_MembershipType extends CRM_Member_Form_MembershipConfig { } $this->applyFilter('__ALL__', 'trim'); - $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'name'), TRUE); + $this->addField('name', [], TRUE); + $this->addField('description'); + $this->addField('minimum_fee'); + $this->addField('duration_unit', [], TRUE); + $this->addField('period_type', [], TRUE); + $this->addField('is_active'); + $this->addField('weight'); + $this->addField('max_related'); $this->addRule('name', ts('A membership type with this name already exists. Please select another name.'), 'objectExists', array('CRM_Member_DAO_MembershipType', $this->_id) ); - $this->add('text', 'description', ts('Description'), - CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'description') - ); - $this->add('text', 'minimum_fee', ts('Minimum Fee'), - CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'minimum_fee') - ); $this->addRule('minimum_fee', ts('Please enter a monetary value for the Minimum Fee.'), 'money'); - $this->addSelect('duration_unit', array(), TRUE); - - // period type - $this->addSelect('period_type', array(), TRUE); - $this->add('text', 'duration_interval', ts('Duration Interval'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'duration_interval') ); @@ -193,12 +189,7 @@ class CRM_Member_Form_MembershipType extends CRM_Member_Form_MembershipConfig { $memberRel = $this->add('select', 'relationship_type_id', ts('Relationship Type'), $relTypeInd, FALSE, array('class' => 'crm-select2 huge', 'multiple' => 1)); - $this->addSelect('visibility', array('placeholder' => NULL, 'option_url' => NULL)); - - $this->add('text', 'weight', ts('Order'), - CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'weight') - ); - $this->add('checkbox', 'is_active', ts('Enabled?')); + $this->addField('visibility', array('placeholder' => NULL, 'option_url' => NULL)); $membershipRecords = FALSE; if ($this->_action & CRM_Core_Action::UPDATE) { @@ -211,10 +202,6 @@ class CRM_Member_Form_MembershipType extends CRM_Member_Form_MembershipConfig { $this->assign('membershipRecordsExists', $membershipRecords); - $this->add('text', 'max_related', ts('Max related'), - CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'max_related') - ); - $this->addFormRule(array('CRM_Member_Form_MembershipType', 'formRule')); $this->assign('membershipTypeId', $this->_id); diff --git a/xml/schema/Member/MembershipType.xml b/xml/schema/Member/MembershipType.xml index 0c37b8314e..0286b74680 100644 --- a/xml/schema/Member/MembershipType.xml +++ b/xml/schema/Member/MembershipType.xml @@ -49,6 +49,7 @@ Name of Membership Type Text + 1.5 @@ -60,6 +61,7 @@ TextArea 6 50 + 255 true @@ -124,6 +126,7 @@ 0 Text + 1.5 @@ -213,6 +216,7 @@ 4.3 Text + @@ -282,6 +286,7 @@ 1.5 CheckBox + -- 2.25.1