class XmlSitemapEnginesSettingsForm in XML sitemap 8
Same name and namespace in other branches
- 2.x xmlsitemap_engines/src/Form/XmlSitemapEnginesSettingsForm.php \Drupal\xmlsitemap_engines\Form\XmlSitemapEnginesSettingsForm
Configure xmlsitemap engines 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\xmlsitemap_engines\Form\XmlSitemapEnginesSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of XmlSitemapEnginesSettingsForm
1 string reference to 'XmlSitemapEnginesSettingsForm'
- xmlsitemap_engines.routing.yml in xmlsitemap_engines/
xmlsitemap_engines.routing.yml - xmlsitemap_engines/xmlsitemap_engines.routing.yml
File
- xmlsitemap_engines/
src/ Form/ XmlSitemapEnginesSettingsForm.php, line 17
Namespace
Drupal\xmlsitemap_engines\FormView source
class XmlSitemapEnginesSettingsForm extends ConfigFormBase {
/**
* The state service.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* The date formatter service.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $date;
/**
* Constructs a new XmlSitemapCustomAddForm object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date
* The date service.
* @param \Drupal\Core\State\StateInterface $state
* The state store service.
*/
public function __construct(ConfigFactoryInterface $config_factory, DateFormatterInterface $date, StateInterface $state) {
parent::__construct($config_factory);
$this->date = $date;
$this->state = $state;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('date.formatter'), $container
->get('state'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'xmlsitemap_engines_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'xmlsitemap_engines.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Build the list of support engines for the checkboxes options.
$engines = xmlsitemap_engines_get_engine_info();
$engine_options = [];
foreach ($engines as $engine => $engine_info) {
$engine_options[$engine] = $engine_info['name'];
}
asort($engine_options);
$form['engines'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Submit the sitemap to the following engines'),
'#default_value' => $this
->config('xmlsitemap_engines.settings')
->get('engines'),
'#options' => $engine_options,
];
$lifetimes = [
3600,
10800,
21600,
32400,
43200,
86400,
172800,
259200,
604800,
604800 * 2,
604800 * 4,
];
$lifetimes = array_combine($lifetimes, $lifetimes);
$format_lifetimes = [];
foreach ($lifetimes as $value) {
$format_lifetimes[$value] = $this->date
->formatInterval($value);
}
$form['minimum_lifetime'] = [
'#type' => 'select',
'#title' => $this
->t('Do not submit more often than every'),
'#options' => $format_lifetimes,
'#default_value' => $this
->config('xmlsitemap_engines.settings')
->get('minimum_lifetime'),
];
$form['xmlsitemap_engines_submit_updated'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Only submit if the sitemap has been updated since the last submission.'),
'#default_value' => $this->state
->get('xmlsitemap_engines_submit_updated'),
];
$form['custom_urls'] = [
'#type' => 'textarea',
'#title' => $this
->t('Custom submission URLs'),
'#description' => $this
->t('Enter one URL per line. The token [sitemap] will be replaced with the URL to your sitemap. For example: %example-before would become %example-after.', [
'%example-before' => 'http://example.com/ping?[sitemap]',
'%example-after' => xmlsitemap_engines_prepare_url('http://example.com/ping?[sitemap]', Url::fromRoute('xmlsitemap.sitemap_xml', [], [
'absolute' => TRUE,
])
->toString()),
]),
'#default_value' => $this
->config('xmlsitemap_engines.settings')
->get('custom_urls'),
'#rows' => 2,
'#wysiwyg' => FALSE,
];
// Ensure the xmlsitemap_engines variable gets filtered to a simple array.
$form['array_filter'] = [
'#type' => 'value',
'#value' => TRUE,
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
$custom_urls = $form_state
->getValue('custom_urls');
$custom_urls = preg_split('/[\\r\\n]+/', $custom_urls, -1, PREG_SPLIT_NO_EMPTY);
foreach ($custom_urls as $custom_url) {
$url = xmlsitemap_engines_prepare_url($custom_url, '');
if (!UrlHelper::isValid($url, TRUE)) {
$form_state
->setErrorByName($custom_url, $this
->t('Invalid URL %url.', [
'%url' => $custom_url,
]));
}
}
$custom_urls = implode("\n", $custom_urls);
$form_state
->setValue('custom_urls', $custom_urls);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$state_variables = xmlsitemap_engines_state_variables();
$keys = [
'engines',
'minimum_lifetime',
'xmlsitemap_engines_submit_updated',
'custom_urls',
];
$config = $this
->config('xmlsitemap_engines.settings');
$values = $form_state
->getValues();
foreach ($keys as $key) {
if (isset($state_variables[$key])) {
$this->state
->set($key, $values[$key]);
}
else {
$config
->set($key, $values[$key]);
}
}
$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. | |
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. | |
XmlSitemapEnginesSettingsForm:: |
protected | property | The date formatter service. | |
XmlSitemapEnginesSettingsForm:: |
protected | property | The state service. | |
XmlSitemapEnginesSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
XmlSitemapEnginesSettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
XmlSitemapEnginesSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
XmlSitemapEnginesSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
XmlSitemapEnginesSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
XmlSitemapEnginesSettingsForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
XmlSitemapEnginesSettingsForm:: |
public | function |
Constructs a new XmlSitemapCustomAddForm object. Overrides ConfigFormBase:: |