3 namespace Drupal\settings_tray\Form;
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;
13 * The off-canvas form handler for the SystemBrandingBlock.
15 * @see settings_tray_block_alter()
19 class SystemBrandingOffCanvasForm extends PluginFormBase implements ContainerInjectionInterface {
24 * @var \Drupal\Core\Block\BlockPluginInterface
31 * @var \Drupal\Core\Config\ConfigFactoryInterface
33 protected $configFactory;
38 * @var \Drupal\Core\Session\AccountInterface
40 protected $currentUser;
43 * SystemBrandingOffCanvasForm constructor.
45 * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
47 * @param \Drupal\Core\Session\AccountInterface $current_user
50 public function __construct(ConfigFactoryInterface $config_factory, AccountInterface $current_user) {
51 $this->configFactory = $config_factory;
52 $this->currentUser = $current_user;
58 public static function create(ContainerInterface $container) {
60 $container->get('config.factory'),
61 $container->get('current_user')
68 public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
69 $form = $this->plugin->buildConfigurationForm($form, $form_state);
71 $form['block_branding']['#type'] = 'details';
72 $form['block_branding']['#weight'] = 10;
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']);
77 $site_config = $this->configFactory->getEditable('system.site');
78 $form['site_information'] = [
80 '#title' => t('Site details'),
82 '#access' => $this->currentUser->hasPermission('administer site configuration'),
84 $form['site_information']['site_name'] = [
85 '#type' => 'textfield',
86 '#title' => t('Site name'),
87 '#default_value' => $site_config->get('name'),
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."),
103 public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
104 $this->plugin->validateConfigurationForm($form, $form_state);
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'])
116 $this->plugin->submitConfigurationForm($form, $form_state);