You are here

public function ConfigDistroImportForm::buildForm in Config Distro 8

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 ConfigSync::buildForm

File

src/Form/ConfigDistroImportForm.php, line 42

Class

ConfigDistroImportForm
Construct the storage changes in a configuration synchronization form.

Namespace

Drupal\config_distro\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);

  // @todo: why is this empty?
  $storage_comparer = $form_state
    ->get('storage_comparer');
  if (!isset($storage_comparer)) {
    $storage_comparer = new StorageComparer($this->syncStorage, $this->activeStorage, $this->configManager);
  }
  foreach ($storage_comparer
    ->getAllCollectionNames() as $collection) {
    if (isset($form[$collection])) {
      foreach (array_keys($form[$collection]) as $config_change_type) {
        if (isset($form[$collection][$config_change_type]['list'])) {
          foreach ($form[$collection][$config_change_type]['list']['#rows'] as &$row) {
            $config_name = $row['name'];
            if ($config_change_type == 'rename') {
              $names = $storage_comparer
                ->extractRenameNames($config_name);
              $route_options = [
                'source_name' => $names['old_name'],
                'target_name' => $names['new_name'],
              ];
            }
            else {
              $route_options = [
                'source_name' => $config_name,
              ];
            }
            if ($collection != StorageInterface::DEFAULT_COLLECTION) {
              $route_name = 'config_distro.diff_collection';
              $route_options['collection'] = $collection;
            }
            else {
              $route_name = 'config_distro.diff';
            }

            // Set the diff url to our own.
            $row['operations']['data']['#links']['view_diff']['url'] = Url::fromRoute($route_name, $route_options);
          }
        }
      }
    }
  }
  return $form;
}