*
* Generated from xml/schema/CRM/Member/MembershipStatus.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:dfe977e53a6b66703ab4eca3560048e6)
+ * (GenCodeChecksum:ea7435287a239f4851dd354150980069)
*/
/**
'entity' => 'MembershipStatus',
'bao' => 'CRM_Member_BAO_MembershipStatus',
'localizable' => 1,
+ 'html' => [
+ 'type' => 'Text',
+ ],
],
'start_event' => [
'name' => 'start_event',
'is_admin' => [
'name' => 'is_admin',
'type' => CRM_Utils_Type::T_BOOLEAN,
- 'title' => ts('Admin Assigned Only?'),
+ 'title' => ts('Administrator Only?'),
'description' => 'Is this status for admin/manual assignment only.',
'table_name' => 'civicrm_membership_status',
'entity' => 'MembershipStatus',
'bao' => 'CRM_Member_BAO_MembershipStatus',
'localizable' => 0,
+ 'html' => [
+ 'type' => 'CheckBox',
+ ],
],
'weight' => [
'name' => 'weight',
'entity' => 'MembershipStatus',
'bao' => 'CRM_Member_BAO_MembershipStatus',
'localizable' => 0,
+ 'html' => [
+ 'type' => 'CheckBox',
+ ],
],
'is_active' => [
'name' => 'is_active',
'entity' => 'MembershipStatus',
'bao' => 'CRM_Member_BAO_MembershipStatus',
'localizable' => 0,
+ 'html' => [
+ 'type' => 'CheckBox',
+ ],
],
'is_reserved' => [
'name' => 'is_reserved',
'entity' => 'MembershipStatus',
'bao' => 'CRM_Member_BAO_MembershipStatus',
'localizable' => 0,
+ 'html' => [
+ 'type' => 'CheckBox',
+ ],
],
];
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
/**
* This class generates form components for Membership Type
*/
-class CRM_Member_Form_MembershipStatus extends CRM_Member_Form_MembershipConfig {
+class CRM_Member_Form_MembershipStatus extends CRM_Core_Form {
+ use CRM_Core_Form_EntityFormTrait;
/**
* Explicitly declare the entity api name.
return 'create';
}
+ /**
+ * Fields for the entity to be assigned to the template.
+ *
+ * Fields may have keys
+ * - name (required to show in tpl from the array)
+ * - description (optional, will appear below the field)
+ * - not-auto-addable - this class will not attempt to add the field using addField.
+ * (this will be automatically set if the field does not have html in it's metadata
+ * or is not a core field on the form's entity).
+ * - help (optional) add help to the field - e.g ['id' => 'id-source', 'file' => 'CRM/Contact/Form/Contact']]
+ * - template - use a field specific template to render this field
+ * @var array
+ */
+ protected $entityFields = [];
+
+ /**
+ * Set entity fields to be assigned to the form.
+ */
+ protected function setEntityFields() {
+ $this->entityFields = [
+ 'label' => [
+ 'name' => 'label',
+ 'description' => ts("Display name for this Membership status (e.g. New, Current, Grace, Expired...)."),
+ 'required' => TRUE,
+ ],
+ 'is_admin' => [
+ 'name' => 'is_admin',
+ 'description' => ts("Check this box if this status is for use by administrative staff only. If checked, this status is never automatically assigned by CiviMember. It is assigned to a contact's Membership by checking the <strong>Status Override</strong> flag when adding or editing the Membership record. Start and End Event settings are ignored for Administrator statuses. EXAMPLE: This setting can be useful for special case statuses like 'Non-expiring', 'Barred' or 'Expelled', etc."),
+ ],
+ ];
+ }
+
+ /**
+ * Set the delete message.
+ *
+ * We do this from the constructor in order to do a translation.
+ */
+ public function setDeleteMessage() {
+ $this->deleteMessage = ts('WARNING: Deleting this option will result in the loss of all membership records of this status.') . ' ' . ts('This may mean the loss of a substantial amount of data, and the action cannot be undone.') . ' ' . ts('Do you want to continue?');
+ }
+
+ public function preProcess() {
+ $this->_id = $this->get('id');
+ $this->_BAOName = 'CRM_Member_BAO_MembershipStatus';
+ }
+
/**
* Set default values for the form. MobileProvider that in edit/view mode
* the default values are retrieved from the database
*
- *
- * @return void
+ * @return array
*/
public function setDefaultValues() {
- $defaults = parent::setDefaultValues();
+ $defaults = array();
+
+ if ($this->getEntityId()) {
+ $params = array('id' => $this->getEntityId());
+ $baoName = $this->_BAOName;
+ $baoName::retrieve($params, $defaults);
+ }
+
+ if ($this->_action & CRM_Core_Action::ADD) {
+ $defaults['is_active'] = 1;
+ }
//finding default weight to be put
if (empty($defaults['weight'])) {
/**
* Build the form object.
- *
- * @return void
*/
public function buildQuickForm() {
+ self::buildQuickEntityForm();
parent::buildQuickForm();
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
- $this->applyFilter('__ALL__', 'trim');
-
if ($this->_id) {
$name = $this->add('text', 'name', ts('Name'),
CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'name')
$name->freeze();
$this->assign('id', $this->_id);
}
- $this->add('text', 'label', ts('Label'),
- CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'label'), TRUE
- );
$this->addRule('label', ts('A membership status with this label already exists. Please select another label.'),
'objectExists', array('CRM_Member_DAO_MembershipStatus', $this->_id, 'name')
);
CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'end_event_adjust_interval')
);
$this->add('checkbox', 'is_current_member', ts('Current Membership?'));
- $this->add('checkbox', 'is_admin', ts('Administrator Only?'));
$this->add('text', 'weight', ts('Order'),
CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'weight')
/**
* Process the form submission.
- *
- *
- * @return void
*/
public function postProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
CRM_Core_Session::setStatus(ts('Selected membership status has been deleted.'), ts('Record Deleted'), 'success');
}
else {
- $params = $ids = array();
// store the submitted values in an array
$params = $this->exportValues();
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
if ($this->_action & CRM_Core_Action::UPDATE) {
- $ids['membershipStatus'] = $this->_id;
+ $params['id'] = $this->getEntityId();
}
$oldWeight = NULL;
if ($this->_id) {
$params['name'] = $params['label'];
}
- $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params, $ids);
+ $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
CRM_Core_Session::setStatus(ts('The membership status \'%1\' has been saved.',
array(1 => $membershipStatus->label)
), ts('Saved'), 'success');