namespace Drupal\Core\Installer\Form;
+use Drupal\Core\Config\FileStorage;
use Drupal\Core\Form\FormBase;
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}
*/
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $install_state = NULL) {
+ global $config_directories;
$form['#title'] = $this->t('Select an installation profile');
$profiles = [];
$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',
* {@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;
}
/**