class SystemBrandingOffCanvasForm
Same name in other branches
- 9 core/modules/system/src/Form/SystemBrandingOffCanvasForm.php \Drupal\system\Form\SystemBrandingOffCanvasForm
- 8.9.x core/modules/system/src/Form/SystemBrandingOffCanvasForm.php \Drupal\system\Form\SystemBrandingOffCanvasForm
- 10 core/modules/system/src/Form/SystemBrandingOffCanvasForm.php \Drupal\system\Form\SystemBrandingOffCanvasForm
The settings_tray form handler for the SystemBrandingBlock.
@internal
Hierarchy
- class \Drupal\Core\Plugin\PluginFormBase implements \Drupal\Core\Plugin\PluginFormInterface, \Drupal\Component\Plugin\PluginAwareInterface
- class \Drupal\system\Form\SystemBrandingOffCanvasForm extends \Drupal\Core\Plugin\PluginFormBase implements \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\StringTranslation\StringTranslationTrait
Expanded class hierarchy of SystemBrandingOffCanvasForm
1 file declares its use of SystemBrandingOffCanvasForm
- SystemBrandingBlock.php in core/
modules/ system/ src/ Plugin/ Block/ SystemBrandingBlock.php
File
-
core/
modules/ system/ src/ Form/ SystemBrandingOffCanvasForm.php, line 19
Namespace
Drupal\system\FormView source
class SystemBrandingOffCanvasForm extends PluginFormBase implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The block plugin.
*
* @var \Drupal\Core\Block\BlockPluginInterface
*/
protected $plugin;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* SystemBrandingOffCanvasForm constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
*/
public function __construct(ConfigFactoryInterface $config_factory, AccountInterface $current_user) {
$this->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' => $this->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' => $this->t('Site name'),
'#default_value' => $site_config->get('name'),
'#required' => TRUE,
];
$form['site_information']['site_slogan'] = [
'#type' => 'textfield',
'#title' => $this->t('Slogan'),
'#default_value' => $site_config->get('slogan'),
'#description' => $this->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);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
PluginFormBase::setPlugin | public | function | Sets the plugin for this object. | Overrides PluginAwareInterface::setPlugin | 1 |
StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | 3 | |
StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. | ||
StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. | ||
StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. | ||
StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. | 2 | |
StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. | ||
SystemBrandingOffCanvasForm::$configFactory | protected | property | The config factory. | ||
SystemBrandingOffCanvasForm::$currentUser | protected | property | The current user. | ||
SystemBrandingOffCanvasForm::$plugin | protected | property | The block plugin. | Overrides PluginFormBase::$plugin | |
SystemBrandingOffCanvasForm::buildConfigurationForm | public | function | Form constructor. | Overrides PluginFormInterface::buildConfigurationForm | |
SystemBrandingOffCanvasForm::create | public static | function | Instantiates a new instance of this class. | Overrides ContainerInjectionInterface::create | |
SystemBrandingOffCanvasForm::submitConfigurationForm | public | function | Form submission handler. | Overrides PluginFormInterface::submitConfigurationForm | |
SystemBrandingOffCanvasForm::validateConfigurationForm | public | function | Form validation handler. | Overrides PluginFormBase::validateConfigurationForm | |
SystemBrandingOffCanvasForm::__construct | public | function | SystemBrandingOffCanvasForm constructor. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.