You are here

protected function CopyRemoteFlow::flowListForm in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x 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 579

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>',
  ];
  $url = $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 = SyncCoreFactory::getSyncCore($url);
  $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();
    $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;
}