class XmlSitemapLinkBundleSettingsForm in XML sitemap 8
Same name and namespace in other branches
- 2.x src/Form/XmlSitemapLinkBundleSettingsForm.php \Drupal\xmlsitemap\Form\XmlSitemapLinkBundleSettingsForm
Configure what entities will be included in sitemap.
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\Form\XmlSitemapLinkBundleSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of XmlSitemapLinkBundleSettingsForm
1 string reference to 'XmlSitemapLinkBundleSettingsForm'
File
- src/
Form/ XmlSitemapLinkBundleSettingsForm.php, line 16
Namespace
Drupal\xmlsitemap\FormView source
class XmlSitemapLinkBundleSettingsForm extends ConfigFormBase {
// @codingStandardsIgnoreStart
private $entity_type;
private $bundle_type;
// @codingStandardsIgnoreEnd
/**
* The state system.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* Constructs a XmlSitemapLinkBundleSettingsForm object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\State\StateInterface $state
* The state system.
*/
public function __construct(ConfigFactoryInterface $config_factory, StateInterface $state) {
parent::__construct($config_factory);
$this->state = $state;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('state'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'xmlsitemap_link_bundle_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'xmlsitemap.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $entity = NULL, $bundle = NULL) {
$this->entity_type = $entity;
$this->bundle_type = $bundle;
$request = $this
->getRequest();
$form['#title'] = $this
->t('@bundle XML sitemap settings', [
'@bundle' => $bundle,
]);
xmlsitemap_add_link_bundle_settings($form, $form_state, $entity, $bundle);
$form['xmlsitemap']['#type'] = 'markup';
$form['xmlsitemap']['#value'] = '';
$form['xmlsitemap']['#access'] = TRUE;
$form['xmlsitemap']['#show_message'] = TRUE;
$destination = $request
->get('destination');
$form['actions']['cancel'] = [
'#type' => 'link',
'#title' => $this
->t('Cancel'),
'#href' => isset($destination) ? $destination : 'admin/config/search/xmlsitemap/settings',
'#weight' => 10,
];
$form = parent::buildForm($form, $form_state);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$bundle = $form['xmlsitemap']['#bundle'];
// Handle new bundles by fetching the proper bundle key value from the form
// state values.
if (empty($bundle)) {
$entity_info = $form['xmlsitemap']['#entity_info'];
if (isset($entity_info['bundle keys']['bundle'])) {
$bundle_key = $entity_info['bundle keys']['bundle'];
if ($form_state
->hasValue($bundle_key)) {
$bundle = $form_state
->getValue($bundle_key);
$form['xmlsitemap']['#bundle'] = $bundle;
}
}
}
$xmlsitemap = $form_state
->getValue('xmlsitemap');
xmlsitemap_link_bundle_settings_save($this->entity_type, $this->bundle_type, $xmlsitemap, TRUE);
$this->state
->set('xmlsitemap_regenerate_needed', TRUE);
$entity_info = $form['xmlsitemap']['#entity_info'];
if (!empty($form['xmlsitemap']['#show_message'])) {
$this
->messenger()
->addStatus($this
->t('XML sitemap settings for the %bundle have been saved.', [
'%bundle' => $entity_info['bundles'][$bundle]['label'],
]));
}
// Unset the form values since we have already saved the bundle settings and
// we don't want these values to get saved as configuration, depending on
// how the form saves the form values.
$form_state
->unsetValue('xmlsitemap');
$form_state
->setRedirect('xmlsitemap.admin_settings');
parent::submitForm($form, $form_state);
}
}
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. | |
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. | |
XmlSitemapLinkBundleSettingsForm:: |
private | property | ||
XmlSitemapLinkBundleSettingsForm:: |
private | property | ||
XmlSitemapLinkBundleSettingsForm:: |
protected | property | The state system. | |
XmlSitemapLinkBundleSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
XmlSitemapLinkBundleSettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
XmlSitemapLinkBundleSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
XmlSitemapLinkBundleSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
XmlSitemapLinkBundleSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
XmlSitemapLinkBundleSettingsForm:: |
public | function |
Constructs a XmlSitemapLinkBundleSettingsForm object. Overrides ConfigFormBase:: |