You are here

class MigrationForm in CMS Content Sync 2.0.x

Same name and namespace in other branches
  1. 2.1.x src/Form/MigrationForm.php \Drupal\cms_content_sync\Form\MigrationForm

Content Sync general settings form.

Hierarchy

Expanded class hierarchy of MigrationForm

1 file declares its use of MigrationForm
Embed.php in src/Controller/Embed.php
1 string reference to 'MigrationForm'
cms_content_sync.routing.yml in ./cms_content_sync.routing.yml
cms_content_sync.routing.yml

File

src/Form/MigrationForm.php, line 15

Namespace

Drupal\cms_content_sync\Form
View source
class MigrationForm extends FormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'migration_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {

    // TODO: Drupal: Recreate Content Sync user password during migration to use stronger 64 characters and also ensure that the old Sync Core can't push updates anylonger; so this must be the last step when switching over.
    $settings = ContentSyncSettings::getInstance();

    // Already registered if this exists.
    $uuid = $settings
      ->getSiteUuid();
    if ($uuid) {

      //$form['#prefix'] = '<div style="display: none;">';

      //$form['#suffix'] = '</div>';
      $form['#attributes']['style'][] = 'display: none;';
      $all_pools = Pool::getAll();
      $pool_options = [];
      foreach ($all_pools as $pool) {
        $pool_options[$pool
          ->id()] = $pool
          ->label();
      }
      $form['export-pools'] = [
        '#prefix' => '<div id="content-sync-migration-export-pools">',
        '#suffix' => '</div>',
        '#title' => 'Export pools',
        '#type' => 'checkboxes',
        '#options' => $pool_options,
      ];
      $all_flows = Flow::getAll();
      $flow_options = [];
      foreach ($all_flows as $flow) {
        $flow_options[$flow
          ->id()] = $flow
          ->label();
      }
      $form['export-flows'] = [
        '#prefix' => '<div id="content-sync-migration-export-flows">',
        '#suffix' => '</div>',
        '#title' => 'Export flows',
        '#type' => 'checkboxes',
        '#options' => $flow_options,
      ];
      $form['skip-flows-test'] = [
        '#prefix' => '<div id="content-sync-migration-skip-flows-test">',
        '#suffix' => '</div>',
        '#title' => 'Skip flows test',
        '#type' => 'checkboxes',
        '#options' => $flow_options,
      ];
      $form['skip-flows-push'] = [
        '#prefix' => '<div id="content-sync-migration-skip-flows-push">',
        '#suffix' => '</div>',
        '#title' => 'Skip flows migration',
        '#type' => 'checkboxes',
        '#options' => $flow_options,
      ];
      $form['skip-flows-pull'] = [
        '#prefix' => '<div id="content-sync-migration-skip-flows-pull">',
        '#suffix' => '</div>',
        '#title' => 'Skip flows migration',
        '#type' => 'checkboxes',
        '#options' => $flow_options,
      ];
      $form['action'] = [
        '#title' => 'Action',
        '#type' => 'radios',
        '#options' => [
          'export-pools' => 'Export Pools',
          'export-flows' => 'Export Flows',
          'skip-flows-test' => 'Skip Flows test',
          'skip-flows-push' => 'Skip Flows push',
          'skip-flows-pull' => 'Skip Flows pull',
          'switch' => 'Switch',
        ],
      ];
      $form['submit'] = [
        '#type' => 'submit',
        '#value' => 'Submit',
        '#button_type' => 'primary',
      ];
    }
    else {
      $url = Url::fromRoute('cms_content_sync_flow.site')
        ->toString();
      \Drupal::messenger()
        ->addMessage('Please register this site first.', 'warning');
      $form['redirect'] = [
        '#markup' => 'This site is not registered yet. Please <a href="' . $url
          ->toString() . '">register first</a>.',
      ];
    }
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    parent::validateForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    if ('export-pools' === $form_state
      ->getValue('action')) {
      Migration::runPoolExport(array_keys(array_filter($form_state
        ->getValue('export-pools'))));
    }
    elseif ('export-flows' === $form_state
      ->getValue('action')) {
      Migration::runFlowExport(array_keys(array_filter($form_state
        ->getValue('export-flows'))));
    }
    elseif ('skip-flows-test' === $form_state
      ->getValue('action')) {
      Migration::skipFlowsTest(array_keys(array_filter($form_state
        ->getValue('skip-flows-test'))));
    }
    elseif ('skip-flows-push' === $form_state
      ->getValue('action')) {
      Migration::skipFlowsPush(array_keys(array_filter($form_state
        ->getValue('skip-flows-push'))));
    }
    elseif ('skip-flows-pull' === $form_state
      ->getValue('action')) {
      Migration::skipFlowsPull(array_keys(array_filter($form_state
        ->getValue('skip-flows-pull'))));
    }
    elseif ('switch' === $form_state
      ->getValue('action')) {
      Migration::runSwitch();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 3
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 3
FormBase::container private function Returns the service container.
FormBase::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create 105
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route.
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
MigrationForm::buildForm public function Form constructor. Overrides FormInterface::buildForm
MigrationForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
MigrationForm::submitForm public function Form submission handler. Overrides FormInterface::submitForm
MigrationForm::validateForm public function Form validation handler. Overrides FormBase::validateForm
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.