function config_admin_sync_form

Helper function to construct the storage changes in a configuration synchronization form.

Parameters

array $form: The form structure to add to. Passed by reference.

array $form_state: The current state of the form. Passed by reference.

\Drupal\Core\Config\StorageInterface $source_storage: The source storage to retrieve differences from.

Return value

array The form with the configuration storage changes.

1 call to config_admin_sync_form()
config_admin_import_form in drupal/core/modules/config/config.admin.inc
Form constructor for configuration import form.

File

drupal/core/modules/config/config.admin.inc, line 28
Admin page callbacks for the config module.

Code

function config_admin_sync_form(array &$form, array &$form_state, StorageInterface $source_storage) {
  $source_list = $source_storage
    ->listAll();
  $config_comparer = new StorageComparer(Drupal::service('config.storage.staging'), Drupal::service('config.storage'));
  if (empty($source_list) || !$config_comparer
    ->createChangelist()
    ->hasChanges()) {
    $form['no_changes'] = array(
      '#markup' => t('There are no configuration changes.'),
    );
    $form['actions']['#access'] = FALSE;
    return $form;
  }
  else {

    // Store the comparer for use in the submit.
    $form_state['storage_comparer'] = $config_comparer;
  }

  // Add the AJAX library to the form for dialog support.
  $form['#attached']['library'][] = array(
    'system',
    'drupal.ajax',
  );
  foreach ($config_comparer
    ->getChangelist() as $config_change_type => $config_files) {
    if (empty($config_files)) {
      continue;
    }

    // @todo A table caption would be more appropriate, but does not have the
    //   visual importance of a heading.
    $form[$config_change_type]['heading'] = array(
      '#type' => 'html_tag',
      '#tag' => 'h3',
    );
    switch ($config_change_type) {
      case 'create':
        $form[$config_change_type]['heading']['#value'] = format_plural(count($config_files), '@count new', '@count new');
        break;
      case 'update':
        $form[$config_change_type]['heading']['#value'] = format_plural(count($config_files), '@count changed', '@count changed');
        break;
      case 'delete':
        $form[$config_change_type]['heading']['#value'] = format_plural(count($config_files), '@count removed', '@count removed');
        break;
    }
    $form[$config_change_type]['list'] = array(
      '#theme' => 'table',
      '#header' => array(
        'Name',
        'Operations',
      ),
    );
    foreach ($config_files as $config_file) {
      $links['view_diff'] = array(
        'title' => t('View differences'),
        'href' => 'admin/config/development/sync/diff/' . $config_file,
        'attributes' => array(
          'class' => array(
            'use-ajax',
          ),
          'data-accepts' => 'application/vnd.drupal-modal',
          'data-dialog-options' => json_encode(array(
            'width' => 700,
          )),
        ),
      );
      $form[$config_change_type]['list']['#rows'][] = array(
        'name' => $config_file,
        'operations' => array(
          'data' => array(
            '#type' => 'operations',
            '#links' => $links,
          ),
        ),
      );
    }
  }
}