X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fsystem%2Fsrc%2FForm%2FSystemBrandingOffCanvasForm.php;fp=web%2Fcore%2Fmodules%2Fsystem%2Fsrc%2FForm%2FSystemBrandingOffCanvasForm.php;h=120a6580062a7320c3df0b99ee8c20d5bb1a0516;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/core/modules/system/src/Form/SystemBrandingOffCanvasForm.php b/web/core/modules/system/src/Form/SystemBrandingOffCanvasForm.php new file mode 100644 index 000000000..120a65800 --- /dev/null +++ b/web/core/modules/system/src/Form/SystemBrandingOffCanvasForm.php @@ -0,0 +1,124 @@ +configFactory = $config_factory; + $this->currentUser = $current_user; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory'), + $container->get('current_user') + ); + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + $form = $this->plugin->buildConfigurationForm($form, $form_state); + + $form['block_branding']['#type'] = 'details'; + $form['block_branding']['#weight'] = 10; + + // Unset links to Site Information form, we can make these changes here. + unset($form['block_branding']['use_site_name']['#description'], $form['block_branding']['use_site_slogan']['#description']); + + $site_config = $this->configFactory->getEditable('system.site'); + // Load the immutable config to load the overrides. + $site_config_immutable = $this->configFactory->get('system.site'); + $form['site_information'] = [ + '#type' => 'details', + '#title' => t('Site details'), + '#open' => TRUE, + '#access' => $this->currentUser->hasPermission('administer site configuration') && !$site_config_immutable->hasOverrides('name') && !$site_config_immutable->hasOverrides('slogan'), + ]; + $form['site_information']['site_name'] = [ + '#type' => 'textfield', + '#title' => t('Site name'), + '#default_value' => $site_config->get('name'), + '#required' => TRUE, + ]; + $form['site_information']['site_slogan'] = [ + '#type' => 'textfield', + '#title' => t('Slogan'), + '#default_value' => $site_config->get('slogan'), + '#description' => t("How this is used depends on your site's theme."), + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { + $this->plugin->validateConfigurationForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + $site_config = $this->configFactory->get('system.site'); + if (AccessResult::allowedIf(!$site_config->hasOverrides('name') && !$site_config->hasOverrides('slogan'))->isAllowed()) { + $site_info = $form_state->getValue('site_information'); + $this->configFactory->getEditable('system.site') + ->set('name', $site_info['site_name']) + ->set('slogan', $site_info['site_slogan']) + ->save(); + } + + $this->plugin->submitConfigurationForm($form, $form_state); + } + +}