Upgraded drupal core with security updates
[yaffs-website] / web / core / lib / Drupal / Core / Installer / Form / SelectProfileForm.php
1 <?php
2
3 namespace Drupal\Core\Installer\Form;
4
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Provides the profile selection form.
10  */
11 class SelectProfileForm extends FormBase {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function getFormId() {
17     return 'install_select_profile_form';
18   }
19
20   /**
21    * {@inheritdoc}
22    */
23   public function buildForm(array $form, FormStateInterface $form_state, $install_state = NULL) {
24     $form['#title'] = $this->t('Select an installation profile');
25
26     $profiles = [];
27     $names = [];
28     foreach ($install_state['profiles'] as $profile) {
29       /** @var $profile \Drupal\Core\Extension\Extension */
30       $details = install_profile_info($profile->getName());
31       // Don't show hidden profiles. This is used by to hide the testing profile,
32       // which only exists to speed up test runs.
33       if ($details['hidden'] === TRUE && !drupal_valid_test_ua()) {
34         continue;
35       }
36       $profiles[$profile->getName()] = $details;
37
38       // Determine the name of the profile; default to file name if defined name
39       // is unspecified.
40       $name = isset($details['name']) ? $details['name'] : $profile->getName();
41       $names[$profile->getName()] = $name;
42     }
43
44     // Display radio buttons alphabetically by human-readable name, but always
45     // put the core profiles first (if they are present in the filesystem).
46     natcasesort($names);
47     if (isset($names['minimal'])) {
48       // If the expert ("Minimal") core profile is present, put it in front of
49       // any non-core profiles rather than including it with them alphabetically,
50       // since the other profiles might be intended to group together in a
51       // particular way.
52       $names = ['minimal' => $names['minimal']] + $names;
53     }
54     if (isset($names['standard'])) {
55       // If the default ("Standard") core profile is present, put it at the very
56       // top of the list. This profile will have its radio button pre-selected,
57       // so we want it to always appear at the top.
58       $names = ['standard' => $names['standard']] + $names;
59     }
60
61     // The profile name and description are extracted for translation from the
62     // .info file, so we can use $this->t() on them even though they are dynamic
63     // data at this point.
64     $form['profile'] = [
65       '#type' => 'radios',
66       '#title' => $this->t('Select an installation profile'),
67       '#title_display' => 'invisible',
68       '#options' => array_map([$this, 't'], $names),
69       '#default_value' => 'standard',
70     ];
71     foreach (array_keys($names) as $profile_name) {
72       $form['profile'][$profile_name]['#description'] = isset($profiles[$profile_name]['description']) ? $this->t($profiles[$profile_name]['description']) : '';
73     }
74     $form['actions'] = ['#type' => 'actions'];
75     $form['actions']['submit'] = [
76       '#type' => 'submit',
77       '#value' => $this->t('Save and continue'),
78       '#button_type' => 'primary',
79     ];
80     return $form;
81   }
82
83   /**
84    * {@inheritdoc}
85    */
86   public function submitForm(array &$form, FormStateInterface $form_state) {
87     global $install_state;
88     $install_state['parameters']['profile'] = $form_state->getValue('profile');
89   }
90
91 }