You are here

public function ConfigSyncImportForm::buildForm in Configuration Synchronizer 8.2

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfigDistroImportForm::buildForm

File

src/Form/ConfigSyncImportForm.php, line 73

Class

ConfigSyncImportForm

Namespace

Drupal\config_sync\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Ensure the filters reflect the current state of the file system.
  $this->configFilterManager
    ->clearCachedDefinitions();
  $form = parent::buildForm($form, $form_state);
  $form['config_sync'] = [
    '#type' => 'container',
  ];

  // Transform the UI to one based on our changelists.
  if ($changelists = $this->configSyncLister
    ->getExtensionChangelists()) {

    // Create a wrapper for the classic UI provided by core.
    $form['classic'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Classic version of configuration change listings'),
      '#weight' => 10,
    ];

    // For each collection, move the original listings coming from core's
    // form.
    foreach ($this
      ->getAllChangelistCollections($changelists) as $collection) {
      if (isset($form[$collection])) {
        $form['classic'][$collection] = $form[$collection];
        unset($form[$collection]);
      }
    }
    foreach ($changelists as $type => $extension_changelists) {
      $form['config_sync'][$type] = $this
        ->buildUpdatesListing($type, $extension_changelists);
    }
    if (!empty($form['actions']['submit'])) {
      $form['actions']['submit']['#value'] = $this
        ->t('Import');
    }
  }
  $update_mode = $this->state
    ->get('config_sync.update_mode', ConfigSyncListerInterface::DEFAULT_UPDATE_MODE);
  $form['config_sync']['advanced'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Advanced'),
    '#description' => $this
      ->t('Select the mode used to merge in updates. Choose "Merge" to merge updates into the site\'s active configuration while retaining any customizations made since the configuration was originally installed. "Merge" is the default and is recommended for most sites. Choose "Partial reset" if you wish available configuration updates to override any customizations you\'ve made to those items. Choose "Full reset" if you wish to discard all customizations made on your site and revert configuration to the state currently provided by installed modules, themes, and the install profile.'),
    '#open' => $update_mode !== ConfigSyncListerInterface::DEFAULT_UPDATE_MODE,
  ];
  $update_options = [
    ConfigSyncListerInterface::UPDATE_MODE_MERGE => $this
      ->t('Merge'),
    ConfigSyncListerInterface::UPDATE_MODE_PARTIAL_RESET => $this
      ->t('Partial reset'),
    ConfigSyncListerInterface::UPDATE_MODE_FULL_RESET => $this
      ->t('Full reset'),
  ];
  $form['config_sync']['advanced']['update_mode'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Update mode'),
    '#options' => $update_options,
    '#default_value' => $update_mode,
  ];
  $form['config_sync']['advanced']['submit'] = [
    '#type' => 'submit',
    '#value' => t('Change update mode'),
    '#submit' => [
      [
        $this,
        'updateModeChange',
      ],
    ],
  ];
  return $form;
}