You are here

protected function FlowForm::fixMissingFormStateFromAjax in CMS Content Sync 2.0.x

Same name and namespace in other branches
  1. 8 src/Form/FlowForm.php \Drupal\cms_content_sync\Form\FlowForm::fixMissingFormStateFromAjax()
  2. 2.1.x src/Form/FlowForm.php \Drupal\cms_content_sync\Form\FlowForm::fixMissingFormStateFromAjax()

AJAX requests will make the form forget the 'edit' status of the bundles, thus their form elements will disappear in the render array (*not in the UI though*), so even though the user still sees them correctly, changes will just not be saved.

Parameters

$form:

5 calls to FlowForm::fixMissingFormStateFromAjax()
FlowForm::disableBundle in src/Form/FlowForm.php
Disable bundle => hide settings.
FlowForm::enableAllReferenced in src/Form/FlowForm.php
Show all field settings not just the summary.
FlowForm::enableBundle in src/Form/FlowForm.php
Enable bundle => show settings..
FlowForm::showAllFields in src/Form/FlowForm.php
Show all field settings not just the summary.
FlowForm::showVersionMismatches in src/Form/FlowForm.php
Show version mismatches. We need to re-set the missing form state here so the form doesn't break when using this button.

File

src/Form/FlowForm.php, line 2052

Class

FlowForm
Form handler for the Flow add and edit forms.

Namespace

Drupal\cms_content_sync\Form

Code

protected function fixMissingFormStateFromAjax($form, FormStateInterface $form_state) {
  foreach ($form as $type_key => $bundle_elements) {
    if (!is_array($bundle_elements)) {
      continue;
    }
    foreach ($bundle_elements as $entity_bundle_name => $elements) {
      if (!is_array($elements)) {
        continue;
      }
      if (isset($elements['edit']) && is_array($elements['edit'])) {
        if (isset($_POST[$type_key][$entity_bundle_name]['edit']) && '1' === $_POST[$type_key][$entity_bundle_name]['edit']) {
          $form_state
            ->setValue([
            $type_key,
            $entity_bundle_name,
            'edit',
          ], '1');
        }
      }
      if (isset($elements['fields']) && is_array($elements['fields'])) {
        if (isset($_POST[$type_key][$entity_bundle_name]['fields']['advanced']['show-all']) && '1' === $_POST[$type_key][$entity_bundle_name]['fields']['advanced']['show-all']) {
          $form_state
            ->setValue([
            $type_key,
            $entity_bundle_name,
            'fields',
            'advanced',
            'show-all',
          ], '1');
        }
      }
    }
  }
}