diff --git a/core/modules/config/config.admin.inc b/core/modules/config/config.admin.inc index 99e4ee9..cf8ed0c 100644 --- a/core/modules/config/config.admin.inc +++ b/core/modules/config/config.admin.inc @@ -5,94 +5,10 @@ * Admin page callbacks for the config module. */ -use Drupal\Core\Config\StorageInterface; use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\OpenModalDialogCommand; /** - * Helper function to construct the storage changes in a configuration synchronization form. - * - * @param array $form - * The form structure to add to. Passed by reference. - * @param array $form_state - * The current state of the form. Passed by reference. - * @param Drupal\Core\Config\StorageInterface $source_storage - * The source storage to retrieve differences from. - * @param Drupal\Core\Config\StorageInterface $target_storage - * The target storage to compare differences to. - */ -function config_admin_sync_form(array &$form, array &$form_state, StorageInterface $source_storage, StorageInterface $target_storage) { - $source_list = $source_storage->listAll(); - if (empty($source_list)) { - $form['no_changes'] = array( - '#markup' => t('There is no configuration to import.'), - ); - $form['actions']['#access'] = FALSE; - return $form; - } - - $config_changes = config_sync_get_changes($source_storage, $target_storage); - if (empty($config_changes)) { - $form['no_changes'] = array( - '#markup' => t('There are no configuration changes.'), - ); - return $form; - } - - // Add the AJAX library to the form for dialog support. - $form['#attached']['library'][] = array('system', 'drupal.ajax'); - - foreach ($config_changes 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( - '#theme' => 'html_tag__h3', - '#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 'change': - $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'), - ), - ); - $form[$config_change_type]['list']['#rows'][] = array( - 'name' => $config_file, - 'operations' => array( - 'data' => array( - '#type' => 'operations', - '#links' => $links, - ), - ), - ); - } - } -} - -/** * Page callback: Shows diff of specificed configuration file. * * @param string $config_file diff --git a/core/modules/config/lib/Drupal/config/Form/ConfigAdminImportForm.php b/core/modules/config/lib/Drupal/config/Form/ConfigAdminImportForm.php index 8999301..6b4a12e 100644 --- a/core/modules/config/lib/Drupal/config/Form/ConfigAdminImportForm.php +++ b/core/modules/config/lib/Drupal/config/Form/ConfigAdminImportForm.php @@ -56,7 +56,7 @@ public function __construct(StorageInterface $source_storage, StorageInterface $ } /** - * Implements \Drupal\Core\ControllerInterface::create(). + * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( @@ -67,16 +67,84 @@ public static function create(ContainerInterface $container) { } /** - * Implements \Drupal\Core\Form\FormInterface::getFormID(). + * {@inheritdoc} */ public function getFormID() { return 'config_admin_import'; } /** - * Implements \Drupal\Core\Form\FormInterface::buildForm(). + * {@inheritdoc} */ public function buildForm(array $form, array &$form_state) { + $source_list = $this->sourceStorage->listAll(); + if (empty($source_list)) { + $form['no_changes'] = array( + '#markup' => t('There is no configuration to import.'), + ); + return $form; + } + + $config_changes = config_sync_get_changes($this->sourceStorage, $this->targetStorage); + if (empty($config_changes)) { + $form['no_changes'] = array( + '#markup' => t('There are no configuration changes.'), + ); + return $form; + } + + // Add the AJAX library to the form for dialog support. + $form['#attached']['library'][] = array('system', 'drupal.ajax'); + + foreach ($config_changes 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( + '#theme' => 'html_tag__h3', + '#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 'change': + $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'), + ), + ); + $form[$config_change_type]['list']['#rows'][] = array( + 'name' => $config_file, + 'operations' => array( + 'data' => array( + '#type' => 'operations', + '#links' => $links, + ), + ), + ); + } + } + $form['actions'] = array( '#type' => 'actions', ); @@ -85,25 +153,23 @@ public function buildForm(array $form, array &$form_state) { '#value' => t('Import all'), ); - module_load_include('inc', 'config', 'config.admin'); - config_admin_sync_form($form, $form_state, $this->sourceStorage, $this->targetStorage); return $form; } /** - * Implements \Drupal\Core\Form\FormInterface::validateForm(). + * {@inheritdoc} */ public function validateForm(array &$form, array &$form_state) { } /** - * Implements \Drupal\Core\Form\FormInterface::validateForm(). + * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { if (!$this->lock->lockMayBeAvailable(CONFIG_IMPORT_LOCK)) { drupal_set_message(t('Another request may be synchronizing configuration already.')); } - else if (config_import()) { + elseif (config_import()) { // Once a sync completes, we empty the staging directory. This prevents // changes from being accidentally overwritten by stray files getting // imported later. @@ -119,4 +185,5 @@ public function submitForm(array &$form, array &$form_state) { drupal_set_message(t('The import failed due to an error. Any errors have been logged.'), 'error'); } } + }