class SettingsForm in Display Suite 8.3
Same name and namespace in other branches
- 8.4 src/Form/SettingsForm.php \Drupal\ds\Form\SettingsForm
- 8.2 src/Form/SettingsForm.php \Drupal\ds\Form\SettingsForm
Configures Display Suite settings for this site.
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\ds\Form\SettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SettingsForm
1 string reference to 'SettingsForm'
File
- src/
Form/ SettingsForm.php, line 19
Namespace
Drupal\ds\FormView source
class SettingsForm extends ConfigFormBase {
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The theme registry used.
*
* @var \Drupal\Core\Theme\Registry
*/
protected $themeRegistry;
/**
* The route builder.
*
* @var \Drupal\Core\Routing\RouteBuilderInterface
*/
protected $routeBuilder;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* Constructs a \Drupal\ds\Form\SettingsForm object.
*
* @param \Drupal\Core\Config\ConfigFactory $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Theme\Registry $theme_registry
* The theme registry used.
* @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder
* The route builder.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
*/
public function __construct(ConfigFactory $config_factory, ModuleHandlerInterface $module_handler, Registry $theme_registry, RouteBuilderInterface $route_builder, EntityFieldManagerInterface $entity_field_manager) {
parent::__construct($config_factory);
$this->moduleHandler = $module_handler;
$this->themeRegistry = $theme_registry;
$this->routeBuilder = $route_builder;
$this->entityFieldManager = $entity_field_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('module_handler'), $container
->get('theme.registry'), $container
->get('router.builder'), $container
->get('entity_field.manager'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'ds_admin_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('ds.settings');
$form['additional_settings'] = [
'#type' => 'vertical_tabs',
'#attached' => [
'library' => [
'ds/admin',
],
],
];
$form['fs1'] = [
'#type' => 'details',
'#title' => $this
->t('Field Templates'),
'#group' => 'additional_settings',
'#weight' => 1,
'#tree' => TRUE,
'#collapsed' => FALSE,
];
$form['fs1']['field_template'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable Field Templates'),
'#description' => $this
->t('Customize the labels and the HTML output of your fields.'),
'#default_value' => $config
->get('field_template'),
];
$form['fs1']['ft-layout-builder'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable field templates in Layout Builder'),
'#description' => $this
->t('Enable field templates on Layout Builder field blocks. Note that disabling this after having configured layout builder field templates will require a cache clear.'),
'#default_value' => $config
->get('ft-layout-builder'),
'#states' => [
'visible' => [
'input[name="fs1[field_template]"]' => [
'checked' => TRUE,
],
],
],
];
$theme_functions = Ds::getFieldLayoutOptions();
$url = new Url('ds.classes');
$description = $this
->t('<br/>Default will output the field as defined in Drupal Core.<br/>' . 'Reset will strip all HTML.<br/>' . 'Minimal adds a simple wrapper around the field.<br/>' . 'There is also an Expert Field Template that gives full control over the HTML, but can only be set per field.<br/><br/>' . 'You can override this setting per field on the "Manage display" screens or when creating fields on the instance level.<br/><br/>' . '<strong>Template suggestions</strong><br/>' . 'You can create .html.twig files as well for these field theme functions, e.g. field--reset.html.twig, field--minimal.html.twig<br/><br/>' . '<label>CSS classes</label>You can add custom CSS classes on the <a href=":url">classes form</a>. These classes can be added to fields using the Default Field Template.<br/><br/>' . '<label>Advanced</label>You can create your own custom field templates plugin. See Drupal\\ds_test\\Plugin\\DsFieldTemplate for an example.', [
':url' => $url
->toString(),
]);
$form['fs1']['ft-default'] = [
'#type' => 'select',
'#title' => $this
->t('Default Field Template'),
'#options' => $theme_functions,
'#default_value' => $config
->get('ft-default'),
'#description' => $description,
'#states' => [
'visible' => [
'input[name="fs1[field_template]"]' => [
'checked' => TRUE,
],
],
],
];
$form['fs1']['ft-show-colon'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show colon'),
'#default_value' => $config
->get('ft-show-colon'),
'#description' => $this
->t('Show the colon on the reset field template.'),
'#states' => [
'visible' => [
'select[name="fs1[ft-default]"]' => [
'value' => 'reset',
],
'input[name="fs1[field_template]"]' => [
'checked' => TRUE,
],
],
],
];
$form['fs3'] = [
'#type' => 'details',
'#title' => $this
->t('Other'),
'#group' => 'additional_settings',
'#weight' => 3,
'#tree' => TRUE,
];
$form['fs3']['use_field_names'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use field names in templates'),
'#default_value' => $config
->get('use_field_names'),
'#description' => $this
->t('Use field names in twig templates instead of the key'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$values = $form_state
->getValues();
$this
->config('ds.settings')
->set('field_template', $values['fs1']['field_template'])
->set('ft-default', $values['fs1']['ft-default'])
->set('ft-show-colon', $values['fs1']['ft-show-colon'])
->set('ft-layout-builder', $values['fs1']['ft-layout-builder'])
->set('use_field_names', $values['fs3']['use_field_names'])
->save();
$this->entityFieldManager
->clearCachedFieldDefinitions();
$this->moduleHandler
->resetImplementations();
$this->themeRegistry
->reset();
$this->routeBuilder
->setRebuildNeeded();
\Drupal::cache('render')
->deleteAll();
if ($this->moduleHandler
->moduleExists('dynamic_page_cache')) {
\Drupal::cache('dynamic_page_cache')
->deleteAll();
}
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'ds.settings',
];
}
}
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 | |
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. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
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. | |
SettingsForm:: |
protected | property | The entity manager. | |
SettingsForm:: |
protected | property | The module handler. | |
SettingsForm:: |
protected | property | The route builder. | |
SettingsForm:: |
protected | property | The theme registry used. | |
SettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
SettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
SettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
SettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
SettingsForm:: |
public | function |
Constructs a \Drupal\ds\Form\SettingsForm object. Overrides ConfigFormBase:: |
|
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. |