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