You are here

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

Same name and namespace in other branches
  1. 8 src/Form/FlowForm.php \Drupal\cms_content_sync\Form\FlowForm::fixMissingFormStateFromAjax()
  2. 2.0.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 1995

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 $entity_type_name => $bundle_elements) {
    if (!is_array($bundle_elements)) {
      continue;
    }
    foreach ($bundle_elements as $bundle_name => $elements) {
      if (!is_array($elements)) {
        continue;
      }
      if (isset($elements['edit']) && is_array($elements['edit'])) {
        if (isset($_POST[$entity_type_name][$bundle_name]['edit']) && '1' === $_POST[$entity_type_name][$bundle_name]['edit']) {
          $form_state
            ->setValue([
            $entity_type_name,
            $bundle_name,
            'edit',
          ], '1');
        }
      }
      if (isset($elements['properties']) && is_array($elements['properties'])) {
        if (isset($_POST[$entity_type_name][$bundle_name]['properties']['advanced']['show-all']) && '1' === $_POST[$entity_type_name][$bundle_name]['properties']['advanced']['show-all']) {
          $form_state
            ->setValue([
            $entity_type_name,
            $bundle_name,
            'properties',
            'advanced',
            'show-all',
          ], '1');
        }
      }
    }
  }
}