class SettingsForm in Content Planner 8
Same name in this branch
- 8 modules/content_kanban/src/Form/SettingsForm.php \Drupal\content_kanban\Form\SettingsForm
- 8 modules/content_calendar/src/Form/SettingsForm.php \Drupal\content_calendar\Form\SettingsForm
Defines a form that configures forms module settings.
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\content_kanban\Form\SettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SettingsForm
3 files declare their use of SettingsForm
- KanbanEntry.php in modules/
content_kanban/ src/ Component/ KanbanEntry.php - KanbanFilterForm.php in modules/
content_kanban/ src/ Form/ KanbanFilterForm.php - KanbanService.php in modules/
content_kanban/ src/ KanbanService.php
1 string reference to 'SettingsForm'
- content_kanban.routing.yml in modules/
content_kanban/ content_kanban.routing.yml - modules/content_kanban/content_kanban.routing.yml
File
- modules/
content_kanban/ src/ Form/ SettingsForm.php, line 15
Namespace
Drupal\content_kanban\FormView source
class SettingsForm extends ConfigFormBase {
/**
* Config name.
*/
const CONFIG_NAME = 'content_kanban.settings';
/**
* Default Date Range value.
*/
const DEFAULT_DATE_RANGE_VALUE = 30;
/**
* The stored config for the form.
*
* @var \Drupal\Core\Config\Config|\Drupal\Core\Config\ImmutableConfig
*/
protected $config;
/**
* The Kanban service.
*
* @var \Drupal\content_kanban\KanbanService
*/
protected $kanbanService;
/**
* Constructor for the Settings Form.
*/
public function __construct(KanbanService $kanbanService, ConfigFactoryInterface $config_factory) {
parent::__construct($config_factory);
$this->kanbanService = $kanbanService;
// Get config.
$this->config = $this
->config(self::CONFIG_NAME);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('content_kanban.kanban_service'), $container
->get('config.factory'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'content_kanban_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'content_kanban.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
// If the Content Calendar module is not enabled, set the use color setting
// to inactive.
if (!$this->kanbanService
->contentCalendarModuleIsEnabled()) {
$this
->saveColorSetting(0);
}
$config = $this
->config(self::CONFIG_NAME);
$form['advice'] = [
'#title' => 'Disclaimer',
'#type' => 'fieldset',
'#weight' => 78,
'#description' => $this
->t('Ensure all workflow state are set as a Default Revision in order to allow kanban table to work properly'),
];
$form['options'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Options'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
];
// Content Calendar colors.
$form['options']['use_content_calendar_colors'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use the defined colors from Content Calendar'),
'#description' => $this
->t('This setting is only available if the Content Calendar is enabled and configured properly.'),
'#default_value' => $config
->get('use_content_calendar_colors'),
'#disabled' => !$this->kanbanService
->contentCalendarModuleIsEnabled(),
];
// Show user thumb checkbox.
$user_picture_field_exists = !$this
->config('field.field.user.user.user_picture')
->isNew();
$form['options']['show_user_thumb'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show thumbnail image of User image'),
'#description' => $this
->t('This option is only available, if the User account has the "user_picture" field. See Account configuration.'),
'#disabled' => !$user_picture_field_exists,
'#default_value' => $this->config
->get('show_user_thumb'),
];
$default_date_range_value = self::DEFAULT_DATE_RANGE_VALUE;
if ($this->config
->get('default_filter_date_range')) {
$default_date_range_value = $this->config
->get('default_filter_date_range');
}
$form['options']['default_filter_date_range'] = [
'#type' => 'select',
'#title' => $this
->t('Date range'),
'#options' => \Drupal\content_kanban\Form\KanbanFilterForm::getDateRangeOptions(),
'#required' => FALSE,
'#empty_value' => '',
'#empty_option' => $this
->t('All'),
'#default_value' => $default_date_range_value,
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Get values.
$values = $form_state
->getValues();
// Get value to use Content Calendar colors.
$use_content_calendar_colors = $values['use_content_calendar_colors'];
// If Content Calendar module is disabled, then disable usage of colors.
if (!$this->kanbanService
->contentCalendarModuleIsEnabled()) {
$use_content_calendar_colors = 0;
}
// Save settings into configuration.
$this
->saveColorSetting($use_content_calendar_colors);
// Save show user image thumbnail option.
$this
->config(self::CONFIG_NAME)
->set('show_user_thumb', $values['show_user_thumb'])
->set('default_filter_date_range', $values['default_filter_date_range'])
->save();
}
/**
* Saves the color setting.
*
* @param int $value
* The "use content calendar colors" setting value.
*/
protected function saveColorSetting($value) {
$this
->config(self::CONFIG_NAME)
->set('use_content_calendar_colors', $value)
->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 | |
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 stored config for the form. | |
SettingsForm:: |
protected | property | The Kanban service. | |
SettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
SettingsForm:: |
constant | Config name. | ||
SettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
SettingsForm:: |
constant | Default Date Range value. | ||
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:: |
protected | function | Saves the color setting. | |
SettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
SettingsForm:: |
public | function |
Constructor for the Settings Form. 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. |