You are here

public function FlowFormExpert::submitForm in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.0.x modules/cms_content_sync_developer/src/Form/FlowFormExpert.php \Drupal\cms_content_sync_developer\Form\FlowFormExpert::submitForm()

Parameters

array $form:

\Drupal\Core\Form\FormStateInterface $form_state:

Overrides FormInterface::submitForm

File

modules/cms_content_sync_developer/src/Form/FlowFormExpert.php, line 84

Class

FlowFormExpert
Content Sync Expert Flow creation form.

Namespace

Drupal\cms_content_sync_developer\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $configurations = $form_state
    ->getValue('configuration');
  $configurations = preg_split("/\r\n|\n|\r/", $configurations);
  $flow_config = [];
  if (is_array($configurations)) {
    foreach ($configurations as &$config) {
      $config = explode('|', $config);
    }
    foreach ($configurations as $key => $item) {
      if ($form_state
        ->getValue('type') == 'pull') {
        $item = [
          'entity_type' => $item[0],
          'bundle' => $item[1],
          'import_configuration' => [
            'behavior' => $item[3],
            'import_deletion' => TRUE,
            'allow_local_deletion_of_import' => TRUE,
            'import_updates' => 'force_and_forbid_editing',
            'import_pools' => [
              $item[2] => $item[3],
            ],
          ],
        ];
      }
      if ($form_state
        ->getValue('type') == 'push') {
        $item = [
          'entity_type' => $item[0],
          'bundle' => $item[1],
          'export_configuration' => [
            'behavior' => $item[4],
            'export_deletion_settings' => TRUE,
            'export_pools' => [
              $item[2] => $item[3],
            ],
          ],
        ];
      }
      $flow_config[$item['entity_type']][$item['bundle']] = $item;
    }
    $flow = Flow::createFlow($form_state
      ->getValue('name'), $form_state
      ->getValue('id'), TRUE, [], $flow_config);

    // Redirect user to flow form.
    $route_paramenters = [
      'cms_content_sync_flow' => $flow,
    ];
    $form_state
      ->setRedirect('entity.cms_content_sync_flow.edit_form', $route_paramenters);
  }
  else {

    // Something went wrong.
    // @todo .
  }
}