-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove inheritance of MembershipConfig form from MembershipStatus form. #12184
Merged
eileenmcnaughton
merged 2 commits into
civicrm:master
from
eileenmcnaughton:entity_form
May 27, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,8 +34,9 @@ | |
/** | ||
* 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. | ||
|
@@ -51,15 +52,71 @@ public function getDefaultContext() { | |
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 | ||
* - required | ||
* @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('You will not be able to delete this membership status if there are existing memberships with this status. You will need to check all your membership status rules afterwards to ensure that a valid status will always be available.') . " " . 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'])) { | ||
|
@@ -70,28 +127,22 @@ public function setDefaultValues() { | |
|
||
/** | ||
* 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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in self::buildQuickEntityForm(); |
||
|
||
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') | ||
); | ||
|
@@ -107,7 +158,6 @@ public function buildQuickForm() { | |
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') | ||
|
@@ -118,9 +168,6 @@ public function buildQuickForm() { | |
|
||
/** | ||
* Process the form submission. | ||
* | ||
* | ||
* @return void | ||
*/ | ||
public function postProcess() { | ||
if ($this->_action & CRM_Core_Action::DELETE) { | ||
|
@@ -133,7 +180,6 @@ public function postProcess() { | |
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); | ||
|
@@ -142,7 +188,7 @@ public function postProcess() { | |
$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) { | ||
|
@@ -155,7 +201,7 @@ public function postProcess() { | |
$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'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accidentally changed to non-mandatory in previous commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bit should probably be in it's own PR as it's unrelated to the other changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RIght - it leverages the fact this PR adds the ability to set required. I'm OK to do that - I was just a bit scared that it could get lost - but if you feel the PR is otherwise mergeable I'll take it out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, leave me to review/test the rest of the PR then first :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattwire Ok - I could pull that part out & do the required bit first & make this depend on that - either way but there is an interdependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed this change is correct. Let's leave it in the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add 'required' to the docblock above too
* - required (Is this field required or not?)