class DomainThemeSwitchConfigForm in Domain Theme Switch 8
Class DomainThemeSwitchConfigForm.
@package Drupal\domain_theme_switch\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\domain_theme_switch\Form\DomainThemeSwitchConfigForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of DomainThemeSwitchConfigForm
1 string reference to 'DomainThemeSwitchConfigForm'
File
- src/
Form/ DomainThemeSwitchConfigForm.php, line 19
Namespace
Drupal\domain_theme_switch\FormView source
class DomainThemeSwitchConfigForm extends ConfigFormBase {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The theme handler.
*
* @var \Drupal\Core\Extension\ThemeHandlerInterface
*/
protected $themeHandler;
/**
* Construct function.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory load.
* @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
* The theme handler.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManager $entity_type_manager, ThemeHandlerInterface $theme_handler) {
parent::__construct($config_factory);
$this->entityTypeManager = $entity_type_manager;
$this->themeHandler = $theme_handler;
}
/**
* Create function return static domain loader configuration.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* Load the ContainerInterface.
*
* @return static
* return domain loader configuration.
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('entity_type.manager'), $container
->get('theme_handler'));
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'domain_theme_switch.settings',
];
}
/**
* Form ID is domain_theme_switch_config_form.
*
* @return string
* Return form ID.
*/
public function getFormId() {
return 'domain_theme_switch_config_form';
}
/**
* Function to get the list of installed themes.
*
* @return array
* The complete theme registry data array.
*/
public function getThemeList() {
$themeName = [];
foreach ($this->themeHandler
->listInfo() as $key => $value) {
$themeName[$key] = $value->info['name'];
}
return $themeName;
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('domain_theme_switch.settings');
$defaultSiteTheme = $this
->config('system.theme')
->get('default');
$defaultAdminTheme = $this
->config('system.theme')
->get('admin');
$themeNames = $this
->getThemeList();
$domains = $this->entityTypeManager
->getStorage('domain')
->loadMultiple();
foreach ($domains as $domain) {
$domainId = $domain
->id();
$hostname = $domain
->get('name');
$form[$domainId] = [
'#type' => 'fieldset',
'#title' => $this
->t('Select Theme for "@domain"', [
'@domain' => $hostname,
]),
];
$form[$domainId][$domainId . '_site'] = [
'#title' => $this
->t('Site theme for domain'),
'#type' => 'select',
'#options' => $themeNames,
'#default_value' => NULL !== $config
->get($domainId . '_site') ? $config
->get($domainId . '_site') : $defaultSiteTheme,
];
$form[$domainId][$domainId . '_admin'] = [
'#title' => $this
->t('Admin theme for domain'),
'#suffix' => $this
->t('Change permission to allow domain admin theme @link.', [
'@link' => Link::fromTextAndUrl($this
->t('change permission'), Url::fromRoute('user.admin_permissions', [], [
'fragment' => 'module-domain_theme_switch',
]))
->toString(),
]),
'#type' => 'select',
'#options' => $themeNames,
'#default_value' => NULL !== $config
->get($domainId . '_admin') ? $config
->get($domainId . '_admin') : $defaultAdminTheme,
];
}
if (count($domains) === 0) {
$form['domain_theme_switch_message'] = [
'#markup' => $this
->t('Zero domain records found. Please @link to create the domain.', [
'@link' => Link::fromTextAndUrl($this
->t('click here'), Url::fromRoute('domain.admin'))
->toString(),
]),
];
return $form;
}
return parent::buildForm($form, $form_state);
}
/**
* Validate function for the form.
*
* @param array $form
* Form items.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* Formstate for validate.
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$domains = $this->entityTypeManager
->getStorage('domain')
->loadMultiple();
$config = $this
->config('domain_theme_switch.settings');
foreach ($domains as $domain) {
$domainId = $domain
->id();
$config
->set($domainId . '_site', $form_state
->getValue($domainId . '_site'));
$config
->set($domainId . '_admin', $form_state
->getValue($domainId . '_admin'));
}
$config
->save();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
DomainThemeSwitchConfigForm:: |
protected | property | The entity type manager. | |
DomainThemeSwitchConfigForm:: |
protected | property | The theme handler. | |
DomainThemeSwitchConfigForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
DomainThemeSwitchConfigForm:: |
public static | function |
Create function return static domain loader configuration. Overrides ConfigFormBase:: |
|
DomainThemeSwitchConfigForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
DomainThemeSwitchConfigForm:: |
public | function |
Form ID is domain_theme_switch_config_form. Overrides FormInterface:: |
|
DomainThemeSwitchConfigForm:: |
public | function | Function to get the list of installed themes. | |
DomainThemeSwitchConfigForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
DomainThemeSwitchConfigForm:: |
public | function |
Validate function for the form. Overrides FormBase:: |
|
DomainThemeSwitchConfigForm:: |
public | function |
Construct function. Overrides ConfigFormBase:: |
|
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |