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

REF Convert forms to standard customData template #13412

Merged
merged 9 commits into from
Jan 11, 2019
34 changes: 19 additions & 15 deletions CRM/Campaign/Form/Petition.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ class CRM_Campaign_Form_Petition extends CRM_Core_Form {
*/
public $_surveyId;

/**
* Explicitly declare the entity api name.
*/
public function getDefaultEntity() {
return 'Survey';
}

/**
* Get the entity id being edited.
*
* @return int|null
*/
public function getEntityId() {
return $this->_surveyId;
}

public function preProcess() {
if (!CRM_Campaign_BAO_Campaign::accessCampaign()) {
CRM_Utils_System::permissionDenied();
Expand All @@ -64,14 +80,8 @@ public function preProcess() {
}
}

// when custom data is included in this page
if (!empty($_POST['hidden_custom'])) {
$this->set('type', 'Event');
$this->set('entityId', $this->_surveyId);
CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'Survey', $this->_surveyId);
CRM_Custom_Form_CustomData::buildQuickForm($this);
CRM_Custom_Form_CustomData::setDefaultValues($this);
}
// Add custom data to form
CRM_Custom_Form_CustomData::addToForm($this);

$session = CRM_Core_Session::singleton();
$url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey');
Expand All @@ -90,8 +100,6 @@ public function preProcess() {

$this->assign('action', $this->_action);
$this->assign('surveyId', $this->_surveyId);
// for custom data
$this->assign('entityID', $this->_surveyId);

if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::DELETE)) {
$this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
Expand Down Expand Up @@ -321,11 +329,7 @@ public function postProcess() {
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0);
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0);

$customFields = CRM_Core_BAO_CustomField::getFields('Survey');
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params,
$this->_surveyId,
'Survey'
);
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->getEntityId(), $this->getDefaultEntity());

$surveyId = CRM_Campaign_BAO_Survey::create($params);

Expand Down
26 changes: 18 additions & 8 deletions CRM/Campaign/Form/Survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ class CRM_Campaign_Form_Survey extends CRM_Core_Form {
*/
protected $_surveyTitle;

/**
* Explicitly declare the entity api name.
*/
public function getDefaultEntity() {
return 'Survey';
}

/**
* Get the entity id being edited.
*
* @return int|null
*/
public function getEntityId() {
return $this->_surveyId;
}

public function preProcess() {
if (!CRM_Campaign_BAO_Campaign::accessCampaign()) {
CRM_Utils_System::permissionDenied();
Expand All @@ -78,14 +94,8 @@ public function preProcess() {
$this->assign('action', $this->_action);
$this->assign('surveyId', $this->_surveyId);

// when custom data is included in this page
if (!empty($_POST['hidden_custom'])) {
$this->set('type', 'Survey');
$this->set('entityId', $this->_surveyId);
CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'Survey', $this->_surveyId);
CRM_Custom_Form_CustomData::buildQuickForm($this);
CRM_Custom_Form_CustomData::setDefaultValues($this);
}
// Add custom data to form
CRM_Custom_Form_CustomData::addToForm($this);

// CRM-11480, CRM-11682
// Preload libraries required by the "Questions" tab
Expand Down
22 changes: 4 additions & 18 deletions CRM/Campaign/Form/Survey/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ class CRM_Campaign_Form_Survey_Main extends CRM_Campaign_Form_Survey {
*/
protected $_context;

/**
* Explicitly declare the entity api name.
*/
public function getDefaultEntity() {
return 'Survey';
}

public function preProcess() {
parent::preProcess();

Expand All @@ -70,11 +63,8 @@ public function preProcess() {
CRM_Utils_System::setTitle(ts('Configure Survey') . ' - ' . $this->_surveyTitle);
}

// when custom data is included in this page
if (!empty($_POST['hidden_custom'])) {
CRM_Custom_Form_CustomData::preProcess($this);
CRM_Custom_Form_CustomData::buildQuickForm($this);
}
// Add custom data to form
CRM_Custom_Form_CustomData::addToForm($this);

if ($this->_name != 'Petition') {
$url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey');
Expand All @@ -93,8 +83,6 @@ public function preProcess() {

$this->assign('action', $this->_action);
$this->assign('surveyId', $this->_surveyId);
// for custom data
$this->assign('entityID', $this->_surveyId);
}

/**
Expand Down Expand Up @@ -195,10 +183,8 @@ public function postProcess() {
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0);
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0);

$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params,
$this->_surveyId,
'Survey'
);
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->getEntityId(), $this->getDefaultEntity());

$survey = CRM_Campaign_BAO_Survey::create($params);
$this->_surveyId = $survey->id;

Expand Down
46 changes: 36 additions & 10 deletions CRM/Case/Form/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,36 @@ class CRM_Case_Form_Case extends CRM_Core_Form {
*/
public $_caseTypeId = NULL;

/**
* Explicitly declare the entity api name.
*/
public function getDefaultEntity() {
return 'Case';
}

/**
* Get the entity id being edited.
*
* @return int|null
*/
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 Expand Up @@ -170,18 +200,15 @@ public function preProcess() {
$session = CRM_Core_Session::singleton();
$this->_currentUserId = $session->get('userID');

//when custom data is included in this page
//Add activity custom data is included in this page
CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_activityTypeId, 1, 'Activity');
$className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}";
$className::preProcess($this);
$activityGroupTree = $this->_groupTree;

// for case custom fields to populate with defaults
if (!empty($_POST['hidden_custom'])) {
$params = CRM_Utils_Request::exportValues();
CRM_Custom_Form_CustomData::preProcess($this, NULL, CRM_Utils_Array::value('case_type_id', $params, $this->_caseTypeId), 1, 'Case', $this->_caseId);
CRM_Custom_Form_CustomData::buildQuickForm($this);
}
// Add case custom data to form
$caseTypeId = CRM_Utils_Array::value('case_type_id', CRM_Utils_Request::exportValues(), $this->_caseTypeId);
CRM_Custom_Form_CustomData::addToForm($this, $caseTypeId);

// so that grouptree is not populated with case fields, since the grouptree is used
// for populating activity custom fields.
Expand Down Expand Up @@ -227,10 +254,9 @@ public function buildQuickForm() {
return;
}

//need to assign custom data type and subtype to the template
$this->assign('customDataType', 'Case');

// Add the activity custom data to the form
CRM_Custom_Form_CustomData::buildQuickForm($this);

// we don't want to show button on top of custom form
$this->assign('noPreCustomButton', TRUE);

Expand Down
8 changes: 7 additions & 1 deletion CRM/Custom/Form/CustomData.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ class CRM_Custom_Form_CustomData {
public static function addToForm(&$form, $subType = NULL, $subName = NULL, $groupCount = 1) {
$entityName = $form->getDefaultEntity();
$entityID = $form->getEntityId();
$entitySubType = $form->getEntitySubTypeId($subType);
// 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);
}

// when custom data is included in this page
if (!empty($_POST['hidden_custom'])) {
Expand Down
32 changes: 12 additions & 20 deletions templates/CRM/Activity/Form/Activity.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -280,31 +280,23 @@


{if $action eq 1 or $action eq 2 or $context eq 'search' or $context eq 'smog'}
{*include custom data js file*}
{include file="CRM/common/customData.tpl"}
{literal}
<script type="text/javascript">
CRM.$(function($) {
var doNotNotifyAssigneeFor = {/literal}{$doNotNotifyAssigneeFor|@json_encode}{literal};
$('#activity_type_id').change(function() {
if ($.inArray($(this).val(), doNotNotifyAssigneeFor) != -1) {
$('#notify_assignee_msg').hide();
}
else {
$('#notify_assignee_msg').show();
}
CRM.$(function($) {
var doNotNotifyAssigneeFor = {/literal}{$doNotNotifyAssigneeFor|@json_encode}{literal};
$('#activity_type_id').change(function() {
if ($.inArray($(this).val(), doNotNotifyAssigneeFor) != -1) {
$('#notify_assignee_msg').hide();
}
else {
$('#notify_assignee_msg').show();
}
});
});

{/literal}
{if $customDataSubType}
CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
{else}
CRM.buildCustomData( '{$customDataType}' );
{/if}
{literal}
});
</script>
{/literal}

{include file="CRM/common/customDataBlock.tpl"}
{/if}
</div>{* end of form block*}

Expand Down
18 changes: 1 addition & 17 deletions templates/CRM/Campaign/Form/Campaign.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,10 @@
</tr>
</table>

<div id="customData"></div>
{include file="CRM/common/customDataBlock.tpl"}

{/if}
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="bottom"}
</div>
</div>

{* include custom data js *}
{include file="CRM/common/customData.tpl"}

{literal}
<script type="text/javascript">
CRM.$(function($) {
{/literal}{if $customDataSubType}
CRM.buildCustomData( '{$customDataType}', {$customDataSubType} );
{else}
CRM.buildCustomData( '{$customDataType}' );
{/if}
{literal}
});
</script>
{/literal}
13 changes: 1 addition & 12 deletions templates/CRM/Campaign/Form/Petition.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,7 @@
</td>
</tr>
</table>
<div id="customData"></div>
{*include custom data js file*}
{include file="CRM/common/customData.tpl"}
{literal}
<script type="text/javascript">
CRM.$(function($) {
{/literal}
CRM.buildCustomData( 'Survey' );
{literal}
});
</script>
{/literal}
{include file="CRM/common/customDataBlock.tpl"}
{/if}
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
</div>
Expand Down
23 changes: 1 addition & 22 deletions templates/CRM/Campaign/Form/Survey/Main.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,10 @@
</tr>
<tr class="crm-campaign-form-block-custom_data">
<td colspan="2">
<div id="customData"></div>
{include file="CRM/common/customDataBlock.tpl"}
</td>
</tr>
</table>
<div id="customData"></div>
{*include custom data js file*}
{include file="CRM/common/customData.tpl"}
{literal}
<script type="text/javascript">
CRM.$(function($) {
{/literal}
CRM.buildCustomData( 'Survey' );
{literal}
});
</script>
{/literal}
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
</div>

Expand All @@ -116,12 +104,3 @@
});
</script>
{/literal}
{literal}
<script type="text/javascript">
CRM.$(function($) {
{/literal}
CRM.buildCustomData( 'Survey' );
{literal}
});
</script>
{/literal}
Loading