Skip to content
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

Fix unreleased regression - fatal when editing relationship type Employer #12257

Merged
merged 1 commit into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions CRM/Admin/Form/RelationshipType.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class CRM_Admin_Form_RelationshipType extends CRM_Admin_Form {
* - help (option) 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
* - is_freeze (field should be frozen).
*
* @var array
*/
protected $entityFields = [];
Expand Down Expand Up @@ -102,6 +104,8 @@ public function setDeleteMessage() {
* Build the form object.
*/
public function buildQuickForm() {
$isReserved = ($this->_id && CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $this->_id, 'is_reserved'));
$this->entityFields['is_active']['is_freeze'] = $isReserved;

self::buildQuickEntityForm();
if ($this->_action & CRM_Core_Action::DELETE) {
Expand All @@ -116,25 +120,14 @@ public function buildQuickForm() {
);

$contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, TRUE, '__');

// add select for contact type
$this->add('select', 'contact_types_a', ts('Contact Type A') . ' ',
array(
'' => ts('All Contacts'),
) + $contactTypes
);
$this->add('select', 'contact_types_b', ts('Contact Type B') . ' ',
array(
'' => ts('All Contacts'),
) + $contactTypes
);

//only selected field should be allow for edit, CRM-4888
if ($this->_id &&
CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $this->_id, 'is_reserved')
) {
foreach (array('contactTypeA', 'contactTypeB', 'isActive') as $field) {
$$field->freeze();
foreach (['contact_types_a' => ts('Contact Type A'), 'contact_types_b' => ts('Contact Type B')] as $name => $label) {
$element = $this->add('select', $name, $label . ' ',
array(
'' => ts('All Contacts'),
) + $contactTypes
);
if ($isReserved) {
$element->freeze();
}
}

Expand Down
5 changes: 4 additions & 1 deletion CRM/Core/Form/EntityFormTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ protected function setTranslatedFields() {
protected function addEntityFieldsToTemplate() {
foreach ($this->getEntityFields() as $fieldSpec) {
if (empty($fieldSpec['not-auto-addable'])) {
$this->addField($fieldSpec['name'], [], CRM_Utils_Array::value('required', $fieldSpec));
$element = $this->addField($fieldSpec['name'], [], CRM_Utils_Array::value('required', $fieldSpec));
if (!empty($fieldSpec['is_freeze'])) {
$element->freeze();
}
}
}
}
Expand Down