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

Add function to set entitySubType for entity forms #16017

Merged
merged 1 commit into from
Jan 23, 2020
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
14 changes: 0 additions & 14 deletions CRM/Case/Form/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,6 @@ public function getEntityId() {
return $this->_caseId;
}

/**
* Get the entity subtype ID being edited
*
* @param $subTypeId
*
* @return int|null
*/
public function getEntitySubTypeId($subTypeId) {
if ($subTypeId) {
return $subTypeId;
}
return $this->_caseTypeId;
}

/**
* Build the form object.
*/
Expand Down
20 changes: 12 additions & 8 deletions CRM/Core/Form/EntityFormTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait CRM_Core_Form_EntityFormTrait {
*
* @var int
*/
protected $_entitySubTypeId;
protected $_entitySubTypeId = NULL;

/**
* Get entity fields for the entity to be added to the form.
Expand Down Expand Up @@ -83,17 +83,21 @@ protected function isSuppressCustomData() {
/**
* Get the entity subtype ID being edited
*
* @param $subTypeId
*
* @return int|null
*/
public function getEntitySubTypeId($subTypeId) {
if ($subTypeId) {
return $subTypeId;
}
public function getEntitySubTypeId() {
return $this->_entitySubTypeId;
}

/**
* Set the entity subtype ID being edited
*
* @param $subTypeId
*/
public function setEntitySubTypeId($subTypeId) {
$this->_entitySubTypeId = $subTypeId;
}

/**
* If the custom data is in the submitted data (eg. added via ajax loaded form) add to form.
*/
Expand All @@ -103,7 +107,7 @@ public function addCustomDataToForm() {
}
$customisableEntities = CRM_Core_SelectValues::customGroupExtends();
if (isset($customisableEntities[$this->getDefaultEntity()])) {
CRM_Custom_Form_CustomData::addToForm($this);
CRM_Custom_Form_CustomData::addToForm($this, $this->getEntitySubTypeId());
}
}

Expand Down
13 changes: 5 additions & 8 deletions CRM/Custom/Form/CustomData.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,20 @@ class CRM_Custom_Form_CustomData {
* $params['custom'] = CRM_Core_BAO_CustomField::postProcess($submitted, $this->_id, $this->getDefaultEntity());
*
* @param CRM_Core_Form $form
* @param null|string $subType values stored in civicrm_custom_group.extends_entity_column_value
* @param null|string $entitySubType values stored in civicrm_custom_group.extends_entity_column_value
* e.g Student for contact type
* @param null|string $subName value in civicrm_custom_group.extends_entity_column_id
* @param null|int $groupCount number of entities that could have custom data
* @param null|int $contact_id contact ID associated with the custom data.
*
* @throws \CRM_Core_Exception
*/
public static function addToForm(&$form, $subType = NULL, $subName = NULL, $groupCount = 1, $contact_id = NULL) {
public static function addToForm(&$form, $entitySubType = NULL, $subName = NULL, $groupCount = 1, $contact_id = NULL) {
$entityName = $form->getDefaultEntity();
$entityID = $form->getEntityId();
// FIXME: If the form has been converted to use entityFormTrait then getEntitySubTypeId() will exist.
// However, if it is only partially converted (ie. we've switched customdata to use CRM_Custom_Form_CustomData)
// it won't, so we check if we have a subtype before calling the function.
$entitySubType = NULL;
if ($subType) {
$entitySubType = $form->getEntitySubTypeId($subType);
// If the form has been converted to use entityFormTrait then getEntitySubTypeId() will exist.
if (method_exists($form, 'getEntitySubTypeId') && empty($entitySubType)) {
$entitySubType = $form->getEntitySubTypeId();
}

if ($form->getAction() == CRM_Core_Action::VIEW) {
Expand Down
1 change: 0 additions & 1 deletion templates/CRM/Activity/Form/Activity.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@
{if $action eq 4}
{include file="CRM/Custom/Page/CustomDataView.tpl"}
{else}
<div id="customData"></div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being removed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK - I can see it duplicated in the include file. I'm not wild about it being included with an unrelated change without notes but I think it makes sense.

{include file="CRM/common/customDataBlock.tpl"}
{/if}
</td>
Expand Down