-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
Freeze custom data elements when viewing an entity #12867
Freeze custom data elements when viewing an entity #12867
Conversation
@@ -1639,6 +1639,9 @@ public static function buildQuickForm(&$form, &$groupTree, $inactiveNeeded = FAL | |||
$fieldId = $field['id']; | |||
$elementName = $field['element_name']; | |||
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, $required); | |||
if ($form->getAction() == CRM_Core_Action::VIEW) { | |||
$form->getElement($elementName)->freeze(); | |||
} |
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.
Here we freeze the elements
CRM/Custom/Form/CustomDataByType.php
Outdated
@@ -48,6 +48,7 @@ public function preProcess() { | |||
$this->_entityId = CRM_Utils_Request::retrieve('entityID', 'Positive'); | |||
$this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive'); | |||
$this->_onlySubtype = CRM_Utils_Request::retrieve('onlySubtype', 'Boolean'); | |||
$this->_action = CRM_Utils_Request::retrieve('action', 'String'); | |||
$this->assign('cdType', FALSE); |
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.
Retrieve the action from the AJAX URL
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.
I think type should be "Alphanumeric"
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.
Yep, updated
if ($name == 'action') { | ||
if (!is_numeric($value) && is_string($value)) { | ||
$value = CRM_Core_Action::resolve($value); | ||
} | ||
} |
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 was not allowing an action to be passed in via a numeric ID, only by name (eg. view/edit etc). As the action is assigned to the template numerically and we are creating a URL via the template it would be a real pain to map back to string only to map back to ID again.
@@ -61,6 +61,9 @@ | |||
{if $qfKey} | |||
dataUrl += '&qf=' + '{$qfKey}'; | |||
{/if} | |||
{if $action} | |||
dataUrl += '&action=' + '{$action}'; | |||
{/if} | |||
{literal} |
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.
Add the action to the AJAX URL if it exists in the template.
eca7c8d
to
25cdc89
Compare
@mattwire I'm at the CiviGovernance Sprint in New Jersey and will test this It looks like the failing tests are unrelated. I installed https://github.com/eileenmcnaughton/nz.co.fuzion.relatedpermissions on a test site with and without this pr and was able to replicate the behavior described by @mattwire above. This is ready to be merged from my perspective. |
merging per @alifrumin review |
Overview
When viewing an entity which has custom data (and loads it via AJAX) it should not be editable.
Before
Custom data is editable (but not saved) when viewing:
After
Custom data is not editable when viewing:
Technical Details
Custom data is loaded via AJAX, but the AJAX form does not know what action is being performed. We add the action via the URL on the template and then use that action to freeze the elements if appropriate.
Comments
In this case we are seeing the issue when using the "RelationshipType" form and have the nz.co.fuzion.relatedpermissions extension enabled (which adds custom data to the "RelationshipType" entity.
@eileenmcnaughton This relates to entityform code that we've recently added. It's not a regression I don't think as it's around new "functionality" to view/edit custom data for any entity but it isn't currently working as it should, and I think this fix sorts that.