You are here

protected function CopyRemoteFlow::flowListForm in CMS Content Sync 2.1.x

Same name and namespace in other branches
  1. 8 src/Form/CopyRemoteFlow.php \Drupal\cms_content_sync\Form\CopyRemoteFlow::flowListForm()
  2. 2.0.x src/Form/CopyRemoteFlow.php \Drupal\cms_content_sync\Form\CopyRemoteFlow::flowListForm()

Step 3: Select the remote Flow to import now.

Parameters

bool $collapsed:

Return value

array the form

1 call to CopyRemoteFlow::flowListForm()
CopyRemoteFlow::form in src/Form/CopyRemoteFlow.php
Gets the actual form array to be built.

File

src/Form/CopyRemoteFlow.php, line 578

Class

CopyRemoteFlow
Form handler for the Pool add and edit forms.

Namespace

Drupal\cms_content_sync\Form

Code

protected function flowListForm(array $form, FormStateInterface $form_state) {
  $elements['headline'] = [
    '#markup' => '<br><br><h1>Step 3: Select remote Flow</h1>' . '<div class="messages messages--status">' . $this
      ->t('Select the Flow to copy.<br><br>In the next step you can still replace the pools that are used and switch push/pull from manual to automatic and vice versa.<br>You can also completely switch push and pull. This is especially useful for Content Staging setups where you have one exporting and one pulling site where the config must be mirrored.') . '</div>' . '<br><br>',
  ];
  $v2 = Migration::alwaysUseV2();
  $url = $v2 ? null : ($form_state
    ->getValue('url') ? $form_state
    ->getValue('url') : $_GET['url']);
  $pools = $form_state
    ->getValue('pools');
  $elements['url'] = [
    '#type' => 'hidden',
    '#value' => $url ?? '',
  ];
  $elements['pools'] = [
    '#type' => 'hidden',
    '#value' => $pools,
  ];
  $module_info = \Drupal::service('extension.list.module')
    ->getExtensionInfo('cms_content_sync');
  $client = $url ? SyncCoreFactory::getSyncCore($url) : SyncCoreFactory::getSyncCoreV2();
  $list = $client
    ->getConfigurationService()
    ->listRemoteFlows($module_info['version'] ? $module_info['version'] : 'dev');
  foreach ($pools as $pool_id => $selected) {
    if (!$selected) {
      continue;
    }
    $list
      ->thatUsePool($pool_id);
  }
  $flows = $list
    ->execute();
  if (!count($flows)) {
    $elements['none'] = [
      '#markup' => '<div class="messages messages--warning">' . $this
        ->t('There are no flows exported yet that use the selected pools.') . '</div>',
    ];
  }
  foreach ($flows as $flow) {
    $id = $flow
      ->getId();
    $flow = $this
      ->getFlowConfig($url, $id);
    $data = Yaml::decode($flow
      ->getConfig());

    // Simple Flows can't be copied right now.
    if ($data['variant'] !== Flow::VARIANT_PER_BUNDLE) {
      continue;
    }
    $elements['flow-' . $id] = [
      '#prefix' => '<p>',
      '#suffix' => '</p>',
      '#markup' => $this
        ->t('Copy %name from %site', [
        '%name' => $flow
          ->getName(),
        '%site' => $flow
          ->getSiteName(),
      ]),
      'use' => [
        '#type' => 'submit',
        '#value' => $this
          ->t('Select'),
        '#submit' => [
          '::selectFlow',
        ],
        '#flow_id' => $id,
        '#name' => 'flow-' . $id,
        '#attributes' => [
          'class' => [
            'button--primary',
          ],
        ],
        '#ajax' => [
          'callback' => '::ajaxReturn',
          'wrapper' => self::CONTAINER_ID,
          'method' => 'replace',
          'effect' => 'fade',
          'progress' => [
            'type' => 'throbber',
            'message' => 'loading settings...',
          ],
        ],
      ],
    ];
  }
  return $elements;
}