3 namespace Drupal\system\Form;
5 use Drupal\Core\Access\AccessResult;
6 use Drupal\Core\Config\ConfigFactoryInterface;
7 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
8 use Drupal\Core\Form\FormStateInterface;
9 use Drupal\Core\Plugin\PluginFormBase;
10 use Drupal\Core\Session\AccountInterface;
11 use Symfony\Component\DependencyInjection\ContainerInterface;
14 * The settings_tray form handler for the SystemBrandingBlock.
18 class SystemBrandingOffCanvasForm extends PluginFormBase implements ContainerInjectionInterface {
23 * @var \Drupal\Core\Block\BlockPluginInterface
30 * @var \Drupal\Core\Config\ConfigFactoryInterface
32 protected $configFactory;
37 * @var \Drupal\Core\Session\AccountInterface
39 protected $currentUser;
42 * SystemBrandingOffCanvasForm constructor.
44 * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
46 * @param \Drupal\Core\Session\AccountInterface $current_user
49 public function __construct(ConfigFactoryInterface $config_factory, AccountInterface $current_user) {
50 $this->configFactory = $config_factory;
51 $this->currentUser = $current_user;
57 public static function create(ContainerInterface $container) {
59 $container->get('config.factory'),
60 $container->get('current_user')
67 public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
68 $form = $this->plugin->buildConfigurationForm($form, $form_state);
70 $form['block_branding']['#type'] = 'details';
71 $form['block_branding']['#weight'] = 10;
73 // Unset links to Site Information form, we can make these changes here.
74 unset($form['block_branding']['use_site_name']['#description'], $form['block_branding']['use_site_slogan']['#description']);
76 $site_config = $this->configFactory->getEditable('system.site');
77 // Load the immutable config to load the overrides.
78 $site_config_immutable = $this->configFactory->get('system.site');
79 $form['site_information'] = [
81 '#title' => t('Site details'),
83 '#access' => $this->currentUser->hasPermission('administer site configuration') && !$site_config_immutable->hasOverrides('name') && !$site_config_immutable->hasOverrides('slogan'),
85 $form['site_information']['site_name'] = [
86 '#type' => 'textfield',
87 '#title' => t('Site name'),
88 '#default_value' => $site_config->get('name'),
91 $form['site_information']['site_slogan'] = [
92 '#type' => 'textfield',
93 '#title' => t('Slogan'),
94 '#default_value' => $site_config->get('slogan'),
95 '#description' => t("How this is used depends on your site's theme."),
104 public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
105 $this->plugin->validateConfigurationForm($form, $form_state);
111 public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
112 $site_config = $this->configFactory->get('system.site');
113 if (AccessResult::allowedIf(!$site_config->hasOverrides('name') && !$site_config->hasOverrides('slogan'))->isAllowed()) {
114 $site_info = $form_state->getValue('site_information');
115 $this->configFactory->getEditable('system.site')
116 ->set('name', $site_info['site_name'])
117 ->set('slogan', $site_info['site_slogan'])
121 $this->plugin->submitConfigurationForm($form, $form_state);