Add labels to membership type metadata, allowing for addField method to be used
authoreileen <emcnaughton@wikimedia.org>
Tue, 15 May 2018 02:14:50 +0000 (14:14 +1200)
committereileen <emcnaughton@wikimedia.org>
Tue, 15 May 2018 02:27:58 +0000 (14:27 +1200)
CRM/Core/CodeGen/Specification.php
CRM/Core/Form.php
CRM/Core/I18n/SchemaStructure.php
CRM/Member/DAO/MembershipType.php
CRM/Member/Form/MembershipType.php
xml/schema/Member/MembershipType.xml

index 5d06369437a77e09d017cbd3e143d86673844206..554f3fa27b1db475ccf704af3bd7201f9d36b153 100644 (file)
@@ -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
index 58c332f48bbf7c06634c62e64059b2a490cc3859..0d8286fd15445f1e8536dcf8ab9d2ad5630455da 100644 (file)
@@ -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') {
index 6e06171f2f9e2ff184cdc55814f7d6c3e916116f..2c7f442856afbd1f11d91d75c5fdbad47d00a2fc 100755 (executable)
@@ -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' => [
index e80dfadc6096acdcdc580356115d9c457729968d..f47bc47760b2d60d677ae78de81e794d305d9a27 100644 (file)
@@ -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?',
           ],
         ],
       ];
index a39e17508fb80ef6ee650302bbd8daa6dae1156c..ba2ab9c19aed853ae7c7a0dceb2da6f27fb614f8 100644 (file)
@@ -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);
index 0c37b8314eaae44e732d4372d0bc3545c42b94a9..0286b74680659a91c4fb6ca94ee9300b4baa306a 100644 (file)
@@ -49,6 +49,7 @@
     <comment>Name of Membership Type</comment>
     <html>
       <type>Text</type>
+      <label>Name</label>
     </html>
     <add>1.5</add>
   </field>
@@ -60,6 +61,7 @@
       <type>TextArea</type>
       <rows>6</rows>
       <cols>50</cols>
+      <label>Description</label>
     </html>
     <length>255</length>
     <localizable>true</localizable>
     <default>0</default>
     <html>
       <type>Text</type>
+      <label>Minimum Fee</label>
     </html>
     <add>1.5</add>
   </field>
     <add>4.3</add>
     <html>
       <type>Text</type>
+      <label>Max Related</label>
     </html>
   </field>
   <field>
     <add>1.5</add>
     <html>
       <type>CheckBox</type>
+      <label>Enabled?</label>
     </html>
   </field>
 </table>