3 namespace Drupal\Core\Installer\Form;
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
9 * Provides the profile selection form.
13 class SelectProfileForm extends FormBase {
18 public function getFormId() {
19 return 'install_select_profile_form';
25 public function buildForm(array $form, FormStateInterface $form_state, $install_state = NULL) {
26 $form['#title'] = $this->t('Select an installation profile');
30 foreach ($install_state['profiles'] as $profile) {
31 /** @var $profile \Drupal\Core\Extension\Extension */
32 $details = install_profile_info($profile->getName());
33 // Don't show hidden profiles. This is used by to hide the testing profile,
34 // which only exists to speed up test runs.
35 if ($details['hidden'] === TRUE && !drupal_valid_test_ua()) {
38 $profiles[$profile->getName()] = $details;
40 // Determine the name of the profile; default to file name if defined name
42 $name = isset($details['name']) ? $details['name'] : $profile->getName();
43 $names[$profile->getName()] = $name;
46 // Display radio buttons alphabetically by human-readable name, but always
47 // put the core profiles first (if they are present in the filesystem).
49 if (isset($names['minimal'])) {
50 // If the expert ("Minimal") core profile is present, put it in front of
51 // any non-core profiles rather than including it with them alphabetically,
52 // since the other profiles might be intended to group together in a
54 $names = ['minimal' => $names['minimal']] + $names;
56 if (isset($names['standard'])) {
57 // If the default ("Standard") core profile is present, put it at the very
58 // top of the list. This profile will have its radio button pre-selected,
59 // so we want it to always appear at the top.
60 $names = ['standard' => $names['standard']] + $names;
63 // The profile name and description are extracted for translation from the
64 // .info file, so we can use $this->t() on them even though they are dynamic
65 // data at this point.
68 '#title' => $this->t('Select an installation profile'),
69 '#title_display' => 'invisible',
70 '#options' => array_map([$this, 't'], $names),
71 '#default_value' => 'standard',
73 foreach (array_keys($names) as $profile_name) {
74 $form['profile'][$profile_name]['#description'] = isset($profiles[$profile_name]['description']) ? $this->t($profiles[$profile_name]['description']) : '';
75 // @todo Remove hardcoding of 'demo_umami' profile for a generic warning
76 // system in https://www.drupal.org/project/drupal/issues/2822414.
77 if ($profile_name === 'demo_umami') {
78 $this->addUmamiWarning($form);
81 $form['actions'] = ['#type' => 'actions'];
82 $form['actions']['submit'] = [
84 '#value' => $this->t('Save and continue'),
85 '#button_type' => 'primary',
93 public function submitForm(array &$form, FormStateInterface $form_state) {
94 global $install_state;
95 $install_state['parameters']['profile'] = $form_state->getValue('profile');
99 * Show profile warning if 'demo_umami' profile is selected.
101 protected function addUmamiWarning(array &$form) {
102 // Warning to show when this profile is selected.
103 $description = $form['profile']['demo_umami']['#description'];
104 // Re-defines radio #description to show warning when selected.
105 $form['profile']['demo_umami']['#description'] = [
108 '#markup' => $this->t('This profile is intended for demonstration purposes only.'),
109 '#wrapper_attributes' => [
110 'class' => ['messages', 'messages--warning'],
114 ':input[name="profile"]' => ['value' => 'demo_umami'],
118 'description' => ['#markup' => $description],