Skip to content

Commit

Permalink
Added option to force load options to by pass entity cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jaapjansma committed Nov 24, 2022
1 parent 7abe0d0 commit 9e350d1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
4 changes: 2 additions & 2 deletions cmrf_form_processor.info
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name = CiviMRF Form Processor Webform integration
description = Submit webforms with CiviMRF to CiviCRM Form Processor (https://lab.civicrm.org/extensions/form-procesor)
description = Submit webforms with CiviMRF to CiviCRM Form Processor (https://lab.civicrm.org/extensions/form-procesor)
core = 7.x

package = "CiviMRF"
project = "cmrf_form_processor"
version = "7.x-1.3"
version = "7.x-1.4"

dependencies[] = cmrf_core
dependencies[] = cmrf_webform
Expand Down
37 changes: 26 additions & 11 deletions cmrf_form_processor.module
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,15 @@ function cmrf_form_processor_form_webform_component_edit_form_alter(&$form, &$fo
}

$enabled = false;
$force_load = false;
$option_field = null;
$option_field_params = null;
$cid = $form['cid']['#value'];
if ($cid) {
$component = isset($node->webform['components'][$cid]) ? $node->webform['components'][$cid] : FALSE;
if ($component) {
$enabled = isset($component['extra']['cmrf_form_processor_options_enabled']) && $component['extra']['cmrf_form_processor_options_enabled'] ? true : false;
$force_load = isset($component['extra']['cmrf_form_processor_options_force_load']) && $component['extra']['cmrf_form_processor_options_force_load'] ? true : false;
if ($enabled && isset($component['extra']['cmrf_form_processor_options'])) {
$option_field = $component['extra']['cmrf_form_processor_options'];
}
Expand All @@ -331,7 +333,16 @@ function cmrf_form_processor_form_webform_component_edit_form_alter(&$form, &$fo
'#type' => 'checkbox',
'#title' => t('Load options from CiviMRF Form Processor'),
'#default_value' => $enabled,

);
$form['extra']['cmrf_form_processor_options_force_load'] = array(
'#type' => 'checkbox',
'#title' => t('Force load options from CiviMRF Form Processor (Enable this when you have enabled the entity cache module)'),
'#default_value' => $force_load,
'#states' => array(
'visible' => array(
'input[name="extra[cmrf_form_processor_options_enabled]"]' => array('checked' => true),
),
),
);
$form['extra']['cmrf_form_processor_options'] = array(
'#type' => 'select',
Expand Down Expand Up @@ -432,13 +443,14 @@ function cmrf_form_processor_webform_component_render_alter(&$element, $componen
$profile = !empty($node->cmrf_form_processor_profile) ? $node->cmrf_form_processor_profile : NULL;
$form_processor = $node->cmrf_form_processor_processor;
$enabled = isset($component['extra']['cmrf_form_processor_options_enabled']) && $component['extra']['cmrf_form_processor_options_enabled'] ? TRUE : FALSE;
if (isset($element['#options'])) {
$force_load = isset($component['extra']['cmrf_form_processor_options_force_load']) && $component['extra']['cmrf_form_processor_options_force_load'] ? TRUE : FALSE;
if (isset($element['#options']) && !$force_load) {
if (is_array($element['#options']) && count($element['#options'])) {
$enabled = false;
}
}
if ($enabled && isset($component['extra']['cmrf_form_processor_options'])) {
if (isset($component['extra']['cmrf_loaded_options']) && is_array($component['extra']['cmrf_loaded_options'])) {
if (isset($component['extra']['cmrf_loaded_options']) && is_array($component['extra']['cmrf_loaded_options']) && !$force_load) {
$available_options = $component['extra']['cmrf_loaded_options'];
} else {
$additional_params = [];
Expand Down Expand Up @@ -756,15 +768,18 @@ function cmrf_form_processor_node_load($nodes, $types) {
$form_processor = $node->cmrf_form_processor_processor;
foreach($node->webform['components'] as $cid => $component) {
if (isset($component['extra']['cmrf_form_processor_options_enabled']) && $component['extra']['cmrf_form_processor_options_enabled']) {
$additional_params = [];
if (isset($component['extra']['cmrf_form_processor_options_params'])) {
$additional_params = json_decode(token_replace($component['extra']['cmrf_form_processor_options_params']), TRUE);
$force_load = isset($component['extra']['cmrf_form_processor_options_force_load']) && $component['extra']['cmrf_form_processor_options_force_load'] ? true : false;
if (!$force_load) {
$additional_params = [];
if (isset($component['extra']['cmrf_form_processor_options_params'])) {
$additional_params = json_decode(token_replace($component['extra']['cmrf_form_processor_options_params']), TRUE);
}

$option_field = $component['extra']['cmrf_form_processor_options'];
$available_options = cmrf_form_processor_get_options($form_processor, $option_field, $profile, $additional_params);
$nodes[$cmrf_webform->nid]->webform['components'][$cid]['extra']['items'] = _webform_select_options_to_text($available_options);
$nodes[$cmrf_webform->nid]->webform['components'][$cid]['extra']['cmrf_loaded_options'] = $available_options;
}

$option_field = $component['extra']['cmrf_form_processor_options'];
$available_options = cmrf_form_processor_get_options($form_processor, $option_field, $profile, $additional_params);
$nodes[$cmrf_webform->nid]->webform['components'][$cid]['extra']['items'] = _webform_select_options_to_text($available_options);
$nodes[$cmrf_webform->nid]->webform['components'][$cid]['extra']['cmrf_loaded_options'] = $available_options;
}
}
}
Expand Down

0 comments on commit 9e350d1

Please sign in to comment.