Skip to content

Commit

Permalink
Merge pull request #29417 from eileenmcnaughton/custom
Browse files Browse the repository at this point in the history
Comment functions with deprecation/ preferred method notices
  • Loading branch information
colemanw authored Feb 16, 2024
2 parents 441f495 + bd502f5 commit 7541331
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
18 changes: 18 additions & 0 deletions CRM/Core/Form/EntityFormTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,24 @@ public function addCustomDataToForm() {
if ($this->isSuppressCustomData()) {
return TRUE;
}

/*
@todo - this would be the preferred code here to better support
php8.2 & take advantage of code improvements
Note in this example an additional filter (membership_type_id)
is relevant although for most entities it isn't.
if ($this->isSubmitted()) {
// The custom data fields are added to the form by an ajax form.
// However, if they are not present in the element index they will
// not be available from `$this->getSubmittedValue()` in post process.
// We do not have to set defaults or otherwise render - just add to the element index.
$this->addCustomDataFieldsToForm($this->getDefaultEntity(), array_filter([
'id' => $this->getEntityId(),
'membership_type_id' => $this->getSubmittedValue('membership_type_id')
]));
}
*/

$customisableEntities = CRM_Core_SelectValues::customGroupExtends();
if (isset($customisableEntities[$this->getDefaultEntity()])) {
CRM_Custom_Form_CustomData::addToForm($this, $this->getEntitySubTypeId());
Expand Down
22 changes: 17 additions & 5 deletions CRM/Custom/Form/CustomData.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ class CRM_Custom_Form_CustomData {
/**
* Generic wrapper to add custom data to a form via a single line in preProcess.
*
* $this->getDefaultEntity() must be defined for the form class for this to work.
*
* If the postProcess form cannot use the api & instead uses a BAO function it will need.
* $params['custom'] = CRM_Core_BAO_CustomField::postProcess($submitted, $this->_id, $this->getDefaultEntity());
*
* @param CRM_Core_Form $form
* @param null|string $entitySubType values stored in civicrm_custom_group.extends_entity_column_value
* e.g Student for contact type
Expand All @@ -36,6 +31,23 @@ class CRM_Custom_Form_CustomData {
* @param null|int $contact_id contact ID associated with the custom data.
*
* @throws \CRM_Core_Exception
* @deprecated - preferred code now is to add to ensure the tpl loads custom
* data using the ajax template & add code to `buildForm()` like this
*
* ```
* if ($this->isSubmitted()) {
* $this->addCustomDataFieldsToForm('Membership', array_filter([
* 'id' => $this->getMembershipID(),
* 'membership_type_id' => $this->getSubmittedValue('membership_type_id')
* ]));
* }
* ```
*
* $this->getDefaultEntity() must be defined for the form class for this to work.
*
* If the postProcess form cannot use the api & instead uses a BAO function it will need.
* $params['custom'] = CRM_Core_BAO_CustomField::postProcess($submitted, $this->_id, $this->getDefaultEntity());
*
*/
public static function addToForm(&$form, $entitySubType = NULL, $subName = NULL, $groupCount = 1, $contact_id = NULL) {
$entityName = $form->getDefaultEntity();
Expand Down

0 comments on commit 7541331

Please sign in to comment.