You are here

public function PoolAssignmentForm::submitValues in CMS Content Sync 2.0.x

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

File

src/Form/PoolAssignmentForm.php, line 186

Class

PoolAssignmentForm

Namespace

Drupal\cms_content_sync\Form

Code

public function submitValues(array &$form, FormStateInterface $form_state) {
  $flow_id = $form_state
    ->getValue('flow');
  $pool_id = $form_state
    ->getValue('pool');
  $assignment = $form_state
    ->getValue('assignment');
  $flow = Flow::getAll(false)[$flow_id];
  $type = $flow
    ->getType();
  $pool_index = Flow::TYPE_PUSH === $type ? 'export_pools' : 'import_pools';
  foreach ($flow->sync_entities as &$config) {
    if (!isset($config[$pool_index])) {
      continue;
    }
    $config[$pool_index][$pool_id] = $assignment;
  }
  $flow
    ->save();
  \Drupal::messenger()
    ->addStatus($this
    ->t('Updated pool assignment and saved the Flow.'));
  \Drupal::messenger()
    ->addWarning($this
    ->t('Please export the Flow to apply the changes.'));
}