1 config.admin.inc config_sync_form(array $form, array &$form_state)

Form callback; Build the form for syncing all staged configuration.

File

core/modules/config/config.admin.inc, line 10
Admin page callbacks for the Configuration Management module.

Code

function config_sync_form(array $form, array &$form_state) {
  $form_state['config_statuses'] = config_get_statuses();
  $changed_config_count = count(array_filter($form_state['config_statuses']));
  $modified_times = config_get_modified_times();
  $config_file_errors = array();

  // Add the AJAX library to the form for dialog support.
  $form['#attached']['library'][] = array('system', 'backdrop.ajax');
  $form['#attached']['css'][] = backdrop_get_path('module', 'config') . '/css/config.admin.css';

  $form['description'] = array(
    '#markup' => '<p>' . t('This form allows you to synchronize configuration between sites, such as in development, staging, and production servers. This page shows you the current differences between your current configuration and changes that have been staged for deployment.') . '</p></p>' . t('When the configuration files are in version control, it may be preferable to not empty the staging directory after each sync. The <code>config_sync_clear_staging</code> setting can be disabled in <code>settings.php</code>. Read more about <a href="!url" target="_blank">managing configuration</a>.', array('!url' => url('https://api.backdropcms.org/documentation/working-with-configuration'))) . '</p>',
  );

  if ($changed_config_count === 0) {
    $form['no_changes'] = array(
      '#theme' => 'table',
      '#header' => array('Name', 'Operations'),
      '#rows' => array(),
      '#empty' => t('There are no configuration changes currently staged. You may <a href="!export">export this site\'s configuration</a> or <a href="!import">import to stage new changes</a>.', array('!export' => url('admin/config/development/configuration/full/export'), '!import' => url('admin/config/development/configuration/full/import'))),
    );
    $form['actions']['#access'] = FALSE;
    return $form;
  }

  foreach ($form_state['config_statuses'] as $config_file => $config_change_type) {
    if ($config_change_type === 'error') {
      $config_file_errors[] = $config_file;
    }
    elseif (!is_null($config_change_type)) {
      $links['view_diff'] = array(
        '#type' => 'link',
        '#title' => t('View differences'),
        '#href' => 'admin/config/development/configuration/sync/diff/' . $config_file,
        '#attributes' => array(
          'class' => array('use-ajax'),
          'data-dialog' => 'true',
          'data-dialog-options' => '{"dialogClass": "config-diff"}',
        ),
      );
      $row = array(
        'name' => $config_file,
      );
      if ($config_change_type !== 'delete') {
        $row['date'] = isset($modified_times[$config_file]) ? format_date($modified_times[$config_file], 'short') : '';
      }
      $row['operations'] = array(
        'data' => $links,
      );
      $form[$config_change_type]['list']['#rows'][] = $row;
    }
  }

  foreach (array('create', 'delete', 'update') as $config_change_type) {
    if (!isset($form[$config_change_type])) {
      continue;
    }

    switch ($config_change_type) {
      case 'create':
        $heading = format_plural(count($form[$config_change_type]['list']['#rows']), '@count new configuration', '@count new configuration');
        break;

      case 'update':
        $heading = format_plural(count($form[$config_change_type]['list']['#rows']), '@count configuration changed', '@count configurations changed');
        break;

      case 'delete':
        $heading = format_plural(count($form[$config_change_type]['list']['#rows']), '@count configuration removed', '@count configurations removed');
        break;
    }

    $form[$config_change_type]['heading'] = array(
      '#markup' => '<h3>' . $heading . '</h3>',
      '#weight' => -1,
    );
    $header = ($config_change_type === 'delete') ? array(t('Name'), t('Operations')) : array(t('Name'), t('Modified time'), t('Operations'));
    $form[$config_change_type]['list'] += array(
      '#theme' => 'table',
      '#header' => $header,
    );
  }

  if ($config_file_errors) {
    backdrop_set_message(t('The following configuration files could not be parsed, synchronization cannot proceed.') . theme('item_list', array('items' => $config_file_errors)), 'error');
  }

  $form['actions'] = array(
    '#type' => 'actions'
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Import all'),
    '#access' => $changed_config_count > 0 && empty($config_file_errors),
  );

  return $form;
}