class SettingsForm in Drupal 8
Same name in this branch
- 8 core/modules/media_library/src/Form/SettingsForm.php \Drupal\media_library\Form\SettingsForm
- 8 core/modules/aggregator/src/Form/SettingsForm.php \Drupal\aggregator\Form\SettingsForm
Same name and namespace in other branches
- 9 core/modules/aggregator/src/Form/SettingsForm.php \Drupal\aggregator\Form\SettingsForm
Configures aggregator settings for this site.
@internal
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\aggregator\Form\SettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SettingsForm
1 file declares its use of SettingsForm
- AggregatorPluginSettingsBaseTest.php in core/
modules/ aggregator/ tests/ src/ Unit/ Plugin/ AggregatorPluginSettingsBaseTest.php
1 string reference to 'SettingsForm'
- aggregator.routing.yml in core/
modules/ aggregator/ aggregator.routing.yml - core/modules/aggregator/aggregator.routing.yml
File
- core/
modules/ aggregator/ src/ Form/ SettingsForm.php, line 19
Namespace
Drupal\aggregator\FormView source
class SettingsForm extends ConfigFormBase {
/**
* The aggregator plugin managers.
*
* @var \Drupal\aggregator\Plugin\AggregatorPluginManager[]
*/
protected $managers = [];
/**
* The instantiated plugin instances that have configuration forms.
*
* @var \Drupal\Core\Plugin\PluginFormInterface[]
*/
protected $configurableInstances = [];
/**
* The aggregator plugin definitions.
*
* @var array
*/
protected $definitions = [
'fetcher' => [],
'parser' => [],
'processor' => [],
];
/**
* Constructs a \Drupal\aggregator\SettingsForm object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\aggregator\Plugin\AggregatorPluginManager $fetcher_manager
* The aggregator fetcher plugin manager.
* @param \Drupal\aggregator\Plugin\AggregatorPluginManager $parser_manager
* The aggregator parser plugin manager.
* @param \Drupal\aggregator\Plugin\AggregatorPluginManager $processor_manager
* The aggregator processor plugin manager.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation manager.
*/
public function __construct(ConfigFactoryInterface $config_factory, AggregatorPluginManager $fetcher_manager, AggregatorPluginManager $parser_manager, AggregatorPluginManager $processor_manager, TranslationInterface $string_translation) {
parent::__construct($config_factory);
$this->stringTranslation = $string_translation;
$this->managers = [
'fetcher' => $fetcher_manager,
'parser' => $parser_manager,
'processor' => $processor_manager,
];
// Get all available fetcher, parser and processor definitions.
foreach ([
'fetcher',
'parser',
'processor',
] as $type) {
foreach ($this->managers[$type]
->getDefinitions() as $id => $definition) {
$this->definitions[$type][$id] = new FormattableMarkup('@title <span class="description">@description</span>', [
'@title' => $definition['title'],
'@description' => $definition['description'],
]);
}
}
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('plugin.manager.aggregator.fetcher'), $container
->get('plugin.manager.aggregator.parser'), $container
->get('plugin.manager.aggregator.processor'), $container
->get('string_translation'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'aggregator_admin_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'aggregator.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('aggregator.settings');
// Global aggregator settings.
$form['aggregator_allowed_html_tags'] = [
'#type' => 'textfield',
'#title' => $this
->t('Allowed HTML tags'),
'#size' => 80,
'#maxlength' => 255,
'#default_value' => $config
->get('items.allowed_html'),
'#description' => $this
->t('A space-separated list of HTML tags allowed in the content of feed items. Disallowed tags are stripped from the content.'),
];
// Only show basic configuration if there are actually options.
$basic_conf = [];
if (count($this->definitions['fetcher']) > 1) {
$basic_conf['aggregator_fetcher'] = [
'#type' => 'radios',
'#title' => $this
->t('Fetcher'),
'#description' => $this
->t('Fetchers download data from an external source. Choose a fetcher suitable for the external source you would like to download from.'),
'#options' => $this->definitions['fetcher'],
'#default_value' => $config
->get('fetcher'),
];
}
if (count($this->definitions['parser']) > 1) {
$basic_conf['aggregator_parser'] = [
'#type' => 'radios',
'#title' => $this
->t('Parser'),
'#description' => $this
->t('Parsers transform downloaded data into standard structures. Choose a parser suitable for the type of feeds you would like to aggregate.'),
'#options' => $this->definitions['parser'],
'#default_value' => $config
->get('parser'),
];
}
if (count($this->definitions['processor']) > 1) {
$basic_conf['aggregator_processors'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Processors'),
'#description' => $this
->t('Processors act on parsed feed data, for example they store feed items. Choose the processors suitable for your task.'),
'#options' => $this->definitions['processor'],
'#default_value' => $config
->get('processors'),
];
}
if (count($basic_conf)) {
$form['basic_conf'] = [
'#type' => 'details',
'#title' => $this
->t('Basic configuration'),
'#description' => $this
->t('For most aggregation tasks, the default settings are fine.'),
'#open' => TRUE,
];
$form['basic_conf'] += $basic_conf;
}
// Call buildConfigurationForm() on the active fetcher and parser.
foreach ([
'fetcher',
'parser',
] as $type) {
$active = $config
->get($type);
if (array_key_exists($active, $this->definitions[$type])) {
$instance = $this->managers[$type]
->createInstance($active);
if ($instance instanceof PluginFormInterface) {
$form = $instance
->buildConfigurationForm($form, $form_state);
// Store the instance for validate and submit handlers.
// Keying by ID would bring conflicts, because two instances of a
// different type could have the same ID.
$this->configurableInstances[] = $instance;
}
}
}
// Implementing processor plugins will expect an array at $form['processors'].
$form['processors'] = [];
// Call buildConfigurationForm() for each active processor.
foreach ($this->definitions['processor'] as $id => $definition) {
if (in_array($id, $config
->get('processors'))) {
$instance = $this->managers['processor']
->createInstance($id);
if ($instance instanceof PluginFormInterface) {
$form = $instance
->buildConfigurationForm($form, $form_state);
// Store the instance for validate and submit handlers.
// Keying by ID would bring conflicts, because two instances of a
// different type could have the same ID.
$this->configurableInstances[] = $instance;
}
}
}
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
// Let active plugins validate their settings.
foreach ($this->configurableInstances as $instance) {
$instance
->validateConfigurationForm($form, $form_state);
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$config = $this
->config('aggregator.settings');
// Let active plugins save their settings.
foreach ($this->configurableInstances as $instance) {
$instance
->submitConfigurationForm($form, $form_state);
}
$config
->set('items.allowed_html', $form_state
->getValue('aggregator_allowed_html_tags'));
if ($form_state
->hasValue('aggregator_fetcher')) {
$config
->set('fetcher', $form_state
->getValue('aggregator_fetcher'));
}
if ($form_state
->hasValue('aggregator_parser')) {
$config
->set('parser', $form_state
->getValue('aggregator_parser'));
}
if ($form_state
->hasValue('aggregator_processors')) {
$config
->set('processors', array_filter($form_state
->getValue('aggregator_processors')));
}
$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 | |
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. | |
SettingsForm:: |
protected | property | The instantiated plugin instances that have configuration forms. | |
SettingsForm:: |
protected | property | The aggregator plugin definitions. | |
SettingsForm:: |
protected | property | The aggregator plugin managers. | |
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 |
Form validation handler. Overrides FormBase:: |
|
SettingsForm:: |
public | function |
Constructs a \Drupal\aggregator\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. |