Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / settings_tray / src / Form / SystemBrandingOffCanvasForm.php
1 <?php
2
3 namespace Drupal\settings_tray\Form;
4
5 use Drupal\Core\Config\ConfigFactoryInterface;
6 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
7 use Drupal\Core\Form\FormStateInterface;
8 use Drupal\Core\Plugin\PluginFormBase;
9 use Drupal\Core\Session\AccountInterface;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
11
12 /**
13  * The off-canvas form handler for the SystemBrandingBlock.
14  *
15  * @see settings_tray_block_alter()
16  *
17  * @internal
18  */
19 class SystemBrandingOffCanvasForm extends PluginFormBase implements ContainerInjectionInterface {
20
21   /**
22    * The block plugin.
23    *
24    * @var \Drupal\Core\Block\BlockPluginInterface
25    */
26   protected $plugin;
27
28   /**
29    * The config factory.
30    *
31    * @var \Drupal\Core\Config\ConfigFactoryInterface
32    */
33   protected $configFactory;
34
35   /**
36    * The current user.
37    *
38    * @var \Drupal\Core\Session\AccountInterface
39    */
40   protected $currentUser;
41
42   /**
43    * SystemBrandingOffCanvasForm constructor.
44    *
45    * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
46    *   The config factory.
47    * @param \Drupal\Core\Session\AccountInterface $current_user
48    *   The current user.
49    */
50   public function __construct(ConfigFactoryInterface $config_factory, AccountInterface $current_user) {
51     $this->configFactory = $config_factory;
52     $this->currentUser = $current_user;
53   }
54
55   /**
56    * {@inheritdoc}
57    */
58   public static function create(ContainerInterface $container) {
59     return new static(
60       $container->get('config.factory'),
61       $container->get('current_user')
62     );
63   }
64
65   /**
66    * {@inheritdoc}
67    */
68   public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
69     $form = $this->plugin->buildConfigurationForm($form, $form_state);
70
71     $form['block_branding']['#type'] = 'details';
72     $form['block_branding']['#weight'] = 10;
73
74     // Unset links to Site Information form, we can make these changes here.
75     unset($form['block_branding']['use_site_name']['#description'], $form['block_branding']['use_site_slogan']['#description']);
76
77     $site_config = $this->configFactory->getEditable('system.site');
78     $form['site_information'] = [
79       '#type' => 'details',
80       '#title' => t('Site details'),
81       '#open' => TRUE,
82       '#access' => $this->currentUser->hasPermission('administer site configuration'),
83     ];
84     $form['site_information']['site_name'] = [
85       '#type' => 'textfield',
86       '#title' => t('Site name'),
87       '#default_value' => $site_config->get('name'),
88       '#required' => TRUE,
89     ];
90     $form['site_information']['site_slogan'] = [
91       '#type' => 'textfield',
92       '#title' => t('Slogan'),
93       '#default_value' => $site_config->get('slogan'),
94       '#description' => t("How this is used depends on your site's theme."),
95     ];
96
97     return $form;
98   }
99
100   /**
101    * {@inheritdoc}
102    */
103   public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
104     $this->plugin->validateConfigurationForm($form, $form_state);
105   }
106
107   /**
108    * {@inheritdoc}
109    */
110   public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
111     $site_info = $form_state->getValue('site_information');
112     $this->configFactory->getEditable('system.site')
113       ->set('name', $site_info['site_name'])
114       ->set('slogan', $site_info['site_slogan'])
115       ->save();
116     $this->plugin->submitConfigurationForm($form, $form_state);
117   }
118
119 }