Merge branch '5.11' of https://github.com/civicrm/civicrm-core
[civicrm-core.git] / CRM / Member / Form / MembershipType.php
index 726f3191e05d040d343d59810cd0ec6746f718b9..be97a088108093a1280b75c96ec68629c35402e4 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018                                |
+ | Copyright CiviCRM LLC (c) 2004-2019                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2018
+ * @copyright CiviCRM LLC (c) 2004-2019
  *
  */
 
@@ -62,9 +62,80 @@ class CRM_Member_Form_MembershipType extends CRM_Member_Form_MembershipConfig {
    * Set entity fields to be assigned to the form.
    */
   protected function setEntityFields() {
-    // TODO: Add fields here per CRM/Admin/Form/RelationshipType.php.
-    // ... It's not as easy because MembershipType has multiple conditional fields/javascript etc.
-    $this->entityFields = [];
+    $this->entityFields = [
+      'name' => [
+        'required' => 'TRUE',
+        'name' => 'name',
+        'description' => ts("e.g. 'Student', 'Senior', 'Honor Society'..."),
+      ],
+      'description' => [
+        'name' => 'description',
+        'description' => ts("Description of this membership type for internal use. May include eligibility, benefits, terms, etc."),
+      ],
+      'member_of_contact_id' => [
+        'name' => 'member_of_contact_id',
+        'description' => ts("Members assigned this membership type belong to which organization (e.g. this is for membership in 'Save the Whales - Northwest Chapter'). NOTE: This organization/group/chapter must exist as a CiviCRM Organization type contact."),
+      ],
+      'minimum_fee' => [
+        'name' => 'minimum_fee',
+        'description' => ts('Minimum fee required for this membership type. For free/complimentary memberships - set minimum fee to zero (0). NOTE: When using CiviCRM to process sales taxes this should be the tax exclusive amount.'),
+        'formatter' => 'crmMoney',
+      ],
+      'financial_type_id' => [
+        'name' => 'financial_type_id',
+        'description' => ts('Select the financial type assigned to fees for this membership type (for example \'Membership Fees\'). This is required for all membership types - including free or complimentary memberships.'),
+      ],
+      'auto_renew' => [
+        'name' => 'auto_renew',
+        'options' => CRM_Core_SelectValues::memberAutoRenew(),
+        'place_holder' => ts('You will need to select and configure a supported payment processor (currently Authorize.Net, PayPal Pro, or PayPal Website Standard) in order to offer automatically renewing memberships.'),
+      ],
+      'duration_interval' => [
+        'name' => 'duration_interval',
+        'required' => TRUE,
+      ],
+      'duration_unit' => [
+        'name' => 'duration_unit',
+        'description' => ts('Duration of this membership (e.g. 30 days, 2 months, 5 years, 1 lifetime)'),
+        'required' => TRUE,
+      ],
+      'period_type' => [
+        'name' => 'period_type',
+        'description' => ts("Select 'rolling' if membership periods begin at date of signup. Select 'fixed' if membership periods begin on a set calendar date."),
+        'help' => ['id' => 'period-type', 'file' => "CRM/Member/Page/MembershipType.hlp"],
+        'required' => TRUE,
+      ],
+      'fixed_period_start_day' => [
+        'name' => 'fixed_period_start_day',
+        'description' => ts("Month and day on which a <strong>fixed</strong> period membership or subscription begins. Example: A fixed period membership with Start Day set to Jan 01 means that membership periods would be 1/1/06 - 12/31/06 for anyone signing up during 2006."),
+      ],
+      'fixed_period_rollover_day' => [
+        'name' => 'fixed_period_rollover_day',
+        'description' => ts('Membership signups on or after this date cover the following calendar year as well. Example: If the rollover day is November 30, membership period for signups during December will cover the following year.'),
+      ],
+      'relationship_type_id' => [
+        'name' => 'relationship_type_id',
+      ],
+      'max_related' => [
+        'name' => 'max_related',
+        'description' => ts('Maximum number of related memberships (leave blank for unlimited).'),
+      ],
+      'visibility' => [
+        'name' => 'visibility',
+        'description' => ts("Can this membership type be used for self-service signups ('Public'), or is it only for CiviCRM users with 'Edit Contributions' permission ('Admin')."),
+      ],
+      'weight' => [
+        'name' => 'weight',
+      ],
+      'is_active' => [
+        'name' => 'is_active',
+      ],
+    ];
+
+    if (!CRM_Financial_BAO_PaymentProcessor::hasPaymentProcessorSupporting(array('Recurring'))) {
+      $this->entityFields['auto_renew']['not-auto-addable'] = TRUE;
+      $this->entityFields['auto_renew']['documentation_link'] = ['page' => 'user/contributions/payment-processors'];
+    }
   }
 
   /**
@@ -176,26 +247,17 @@ class CRM_Member_Form_MembershipType extends CRM_Member_Form_MembershipConfig {
     if ($this->_action & CRM_Core_Action::DELETE) {
       return;
     }
-
-    $this->applyFilter('__ALL__', 'trim');
-    $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 is a temporary variable as we work towards moving over towards using the EntityField.tpl.
+    // Fields in this array have been tested & in the tpl have been switched over to metadata.
+    // Note this kinda 'works from the top' - ie. once we hit a field that needs some thought we need
+    // to stop & make that one work.
+    $this->assign('tpl_standardised_fields', ['name', 'description', 'member_of_contact_id', 'minimum_fee']);
 
     $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->addRule('minimum_fee', ts('Please enter a monetary value for the Minimum Fee.'), 'money');
 
-    $this->add('text', 'duration_interval', ts('Duration Interval'),
-      CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'duration_interval')
-    );
-
     $props = array('api' => array('params' => array('contact_type' => 'Organization')));
     $this->addEntityRef('member_of_contact_id', ts('Membership Organization'), $props, TRUE);