Skip to content

Commit

Permalink
Add labels to membership type metadata, allowing for addField method …
Browse files Browse the repository at this point in the history
…to be used
  • Loading branch information
eileenmcnaughton committed May 15, 2018
1 parent 5e5a67c commit 80a9650
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
1 change: 1 addition & 0 deletions CRM/Core/CodeGen/Specification.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ public function getField(&$fieldXML, &$fields) {
$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
Expand Down
3 changes: 2 additions & 1 deletion CRM/Core/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,8 @@ public function addField($name, $props = array(), $required = FALSE, $legacyDate
// 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') {
Expand Down
2 changes: 2 additions & 0 deletions CRM/Core/I18n/SchemaStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,13 @@ static function &widgets() {
'civicrm_membership_type' => [
'name' => [
'type' => "Text",
'label' => "Name",
],
'description' => [
'type' => "TextArea",
'rows' => "6",
'cols' => "50",
'label' => "Description",
],
],
'civicrm_membership_block' => [
Expand Down
7 changes: 6 additions & 1 deletion CRM/Member/DAO/MembershipType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Member/MembershipType.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:f79b8b7075dd740416b24eff8ebd147b)
* (GenCodeChecksum:51b478b01b1ef20a54b1039ccc29d0ab)
*/

/**
Expand Down Expand Up @@ -248,6 +248,7 @@ public static function &fields() {
'localizable' => 1,
'html' => [
'type' => 'Text',
'label' => 'Name',
],
],
'description' => [
Expand All @@ -263,6 +264,7 @@ public static function &fields() {
'localizable' => 1,
'html' => [
'type' => 'TextArea',
'label' => 'Description',
],
],
'member_of_contact_id' => [
Expand Down Expand Up @@ -309,6 +311,7 @@ public static function &fields() {
'localizable' => 0,
'html' => [
'type' => 'Text',
'label' => 'Minimum Fee',
],
],
'duration_unit' => [
Expand Down Expand Up @@ -414,6 +417,7 @@ public static function &fields() {
'localizable' => 0,
'html' => [
'type' => 'Text',
'label' => 'Max Related',
],
],
'visibility' => [
Expand Down Expand Up @@ -500,6 +504,7 @@ public static function &fields() {
'localizable' => 0,
'html' => [
'type' => 'CheckBox',
'label' => 'Enabled?',
],
],
];
Expand Down
31 changes: 9 additions & 22 deletions CRM/Member/Form/MembershipType.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,20 @@ public function buildQuickForm() {
}

$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')
);
Expand Down Expand Up @@ -193,12 +189,7 @@ public function buildQuickForm() {
$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) {
Expand All @@ -211,10 +202,6 @@ public function buildQuickForm() {

$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);
Expand Down
5 changes: 5 additions & 0 deletions xml/schema/Member/MembershipType.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<comment>Name of Membership Type</comment>
<html>
<type>Text</type>
<label>Name</label>
</html>
<add>1.5</add>
</field>
Expand All @@ -60,6 +61,7 @@
<type>TextArea</type>
<rows>6</rows>
<cols>50</cols>
<label>Description</label>
</html>
<length>255</length>
<localizable>true</localizable>
Expand Down Expand Up @@ -124,6 +126,7 @@
<default>0</default>
<html>
<type>Text</type>
<label>Minimum Fee</label>
</html>
<add>1.5</add>
</field>
Expand Down Expand Up @@ -213,6 +216,7 @@
<add>4.3</add>
<html>
<type>Text</type>
<label>Max Related</label>
</html>
</field>
<field>
Expand Down Expand Up @@ -282,6 +286,7 @@
<add>1.5</add>
<html>
<type>CheckBox</type>
<label>Enabled?</label>
</html>
</field>
</table>

0 comments on commit 80a9650

Please sign in to comment.