X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Flib%2FDrupal%2FCore%2FInstaller%2FForm%2FSelectProfileForm.php;h=185a27be3c1373142ee7310f2e53c41758afb56b;hb=refs%2Fheads%2Fd864;hp=488242acee11519f400e57fb2123145d95fb56fc;hpb=af6d1fb995500ae68849458ee10d66abbdcfb252;p=yaffs-website diff --git a/web/core/lib/Drupal/Core/Installer/Form/SelectProfileForm.php b/web/core/lib/Drupal/Core/Installer/Form/SelectProfileForm.php index 488242ace..185a27be3 100644 --- a/web/core/lib/Drupal/Core/Installer/Form/SelectProfileForm.php +++ b/web/core/lib/Drupal/Core/Installer/Form/SelectProfileForm.php @@ -2,6 +2,7 @@ namespace Drupal\Core\Installer\Form; +use Drupal\Core\Config\FileStorage; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; @@ -12,6 +13,13 @@ use Drupal\Core\Form\FormStateInterface; */ class SelectProfileForm extends FormBase { + /** + * The key used in the profile list for the install from config option. + * + * This key must not be a valid profile extension name. + */ + const CONFIG_INSTALL_PROFILE_KEY = '::existing_config::'; + /** * {@inheritdoc} */ @@ -23,6 +31,7 @@ class SelectProfileForm extends FormBase { * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $install_state = NULL) { + global $config_directories; $form['#title'] = $this->t('Select an installation profile'); $profiles = []; @@ -78,6 +87,40 @@ class SelectProfileForm extends FormBase { $this->addUmamiWarning($form); } } + + if (!empty($config_directories[CONFIG_SYNC_DIRECTORY])) { + $sync = new FileStorage($config_directories[CONFIG_SYNC_DIRECTORY]); + $extensions = $sync->read('core.extension'); + $site = $sync->read('system.site'); + if (isset($site['name']) && isset($extensions['profile']) && in_array($extensions['profile'], array_keys($names), TRUE)) { + // Ensure the the profile can be installed from configuration. Install + // profile's which implement hook_INSTALL() are not supported. + // @todo https://www.drupal.org/project/drupal/issues/2982052 Remove + // this restriction. + module_load_install($extensions['profile']); + if (!function_exists($extensions['profile'] . '_install')) { + $form['profile']['#options'][static::CONFIG_INSTALL_PROFILE_KEY] = $this->t('Use existing configuration'); + $form['profile'][static::CONFIG_INSTALL_PROFILE_KEY]['#description'] = [ + 'description' => [ + '#markup' => $this->t('Install %name using existing configuration.', ['%name' => $site['name']]), + ], + 'info' => [ + '#type' => 'item', + '#markup' => $this->t('The configuration from the directory %sync_directory will be used.', ['%sync_directory' => $config_directories[CONFIG_SYNC_DIRECTORY]]), + '#wrapper_attributes' => [ + 'class' => ['messages', 'messages--status'], + ], + '#states' => [ + 'visible' => [ + ':input[name="profile"]' => ['value' => static::CONFIG_INSTALL_PROFILE_KEY], + ], + ], + ], + ]; + } + } + } + $form['actions'] = ['#type' => 'actions']; $form['actions']['submit'] = [ '#type' => 'submit', @@ -91,8 +134,14 @@ class SelectProfileForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - global $install_state; - $install_state['parameters']['profile'] = $form_state->getValue('profile'); + global $install_state, $config_directories; + $profile = $form_state->getValue('profile'); + if ($profile === static::CONFIG_INSTALL_PROFILE_KEY) { + $sync = new FileStorage($config_directories[CONFIG_SYNC_DIRECTORY]); + $profile = $sync->read('core.extension')['profile']; + $install_state['parameters']['existing_config'] = TRUE; + } + $install_state['parameters']['profile'] = $profile; } /**