diff --git a/core/modules/config/config.admin.inc b/core/modules/config/config.admin.inc index e81c582..95c72bc 100644 --- a/core/modules/config/config.admin.inc +++ b/core/modules/config/config.admin.inc @@ -93,53 +93,6 @@ function config_admin_sync_form(array &$form, array &$form_state, StorageInterfa } /** - * Form constructor for configuration import form. - * - * @see config_admin_import_form_submit() - * @see config_import() - */ -function config_admin_import_form($form, &$form_state) { - // Retrieve a list of differences between last known state and active store. - $source_storage = drupal_container()->get('config.storage.staging'); - $target_storage = drupal_container()->get('config.storage'); - - $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array( - '#type' => 'submit', - '#value' => t('Import all'), - ); - - config_admin_sync_form($form, $form_state, $source_storage, $target_storage); - - return $form; -} - -/** - * Form submission handler for config_admin_import_form(). - */ -function config_admin_import_form_submit($form, &$form_state) { - if (!lock()->lockMayBeAvailable(CONFIG_IMPORT_LOCK)) { - drupal_set_message(t('Another request may be synchronizing configuration already.')); - } - else if (config_import()) { - // Once a sync completes, we empty the staging directory. This prevents - // changes from being accidentally overwritten by stray files getting - // imported later. - $source_storage = drupal_container()->get('config.storage.staging'); - foreach ($source_storage->listAll() as $name) { - $source_storage->delete($name); - } - - drupal_flush_all_caches(); - - drupal_set_message(t('The configuration was imported successfully.')); - } - else { - drupal_set_message(t('The import failed due to an error. Any errors have been logged.'), 'error'); - } -} - -/** * Page callback: Shows diff of specificed configuration file. * * @param string $config_file diff --git a/core/modules/config/config.module b/core/modules/config/config.module index e3b6027..c7dd2c4 100644 --- a/core/modules/config/config.module +++ b/core/modules/config/config.module @@ -43,10 +43,7 @@ function config_menu() { $items['admin/config/development/sync'] = array( 'title' => 'Synchronize configuration', 'description' => 'Synchronize configuration changes.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('config_admin_import_form'), - 'access arguments' => array('synchronize configuration'), - 'file' => 'config.admin.inc', + 'route_name' => 'config_admin_import', ); $items['admin/config/development/sync/diff/%'] = array( 'title' => 'Configuration file diff', diff --git a/core/modules/config/config.routing.yml b/core/modules/config/config.routing.yml new file mode 100644 index 0000000..f76dd07 --- /dev/null +++ b/core/modules/config/config.routing.yml @@ -0,0 +1,6 @@ +config_admin_import: + pattern: '/admin/config/development/sync' + defaults: + _form: '\Drupal\config\Form\ConfigAdminImportForm' + requirements: + _permission: 'synchronize configuration' diff --git a/core/modules/config/lib/Drupal/config/Form/ConfigAdminImportForm.php b/core/modules/config/lib/Drupal/config/Form/ConfigAdminImportForm.php new file mode 100644 index 0000000..8d1537a --- /dev/null +++ b/core/modules/config/lib/Drupal/config/Form/ConfigAdminImportForm.php @@ -0,0 +1,122 @@ +sourceStorage = $source_storage; + $this->targetStorage = $target_storage; + $this->lock = $lock; + } + + /** + * Implements \Drupal\Core\ControllerInterface::create(). + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.storage.staging'), + $container->get('config.storage'), + $container->get('lock') + ); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::getFormID(). + */ + public function getFormID() { + return 'config_admin_import'; + } + + /** + * Implements \Drupal\Core\Form\FormInterface::buildForm(). + */ + public function buildForm(array $form, array &$form_state) { + $form['actions'] = array( + '#type' => 'actions', + ); + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => t('Import all'), + ); + + config_admin_sync_form($form, $form_state, $source_storage, $target_storage); + + return $form; + } + + /** + * Implements \Drupal\Core\Form\FormInterface::validateForm(). + */ + public function validateForm(array &$form, array &$form_state) { + } + + /** + * Implements \Drupal\Core\Form\FormInterface::validateForm(). + */ + 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()) { + // Once a sync completes, we empty the staging directory. This prevents + // changes from being accidentally overwritten by stray files getting + // imported later. + foreach ($this->sourceStorage->listAll() as $name) { + $this->sourceStorage->delete($name); + } + + drupal_flush_all_caches(); + + drupal_set_message(t('The configuration was imported successfully.')); + } + else { + drupal_set_message(t('The import failed due to an error. Any errors have been logged.'), 'error'); + } + } +}