You are here

public function ConfigSyncImport::buildForm in Configuration Synchronizer 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/ConfigSyncImport.php, line 41

Class

ConfigSyncImport
Construct the storage changes in a configuration synchronization form.

Namespace

Drupal\config_sync\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');
  $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) {
        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 = array(
              'source_name' => $names['old_name'],
              'target_name' => $names['new_name'],
            );
            $config_name = $this
              ->t('@source_name to @target_name', array(
              '@source_name' => $names['old_name'],
              '@target_name' => $names['new_name'],
            ));
          }
          else {
            $route_options = array(
              'source_name' => $config_name,
            );
          }
          if ($collection != StorageInterface::DEFAULT_COLLECTION) {
            $route_name = 'config_sync.diff_collection';
            $route_options['collection'] = $collection;
          }
          else {
            $route_name = 'config_sync.diff';
          }
          $row['operations']['data']['#links']['view_diff']['url'] = Url::fromRoute($route_name, $route_options);
        }
      }
    }
  }
  return $form;
}