function simple_sitemap_form_alter in Simple XML sitemap 4.x
Same name and namespace in other branches
- 8.3 simple_sitemap.module \simple_sitemap_form_alter()
- 8.2 simple_sitemap.module \simple_sitemap_form_alter()
Implements hook_form_alter().
Adds sitemap settings to entity types that are supported via plugins.
Parameters
$form:
\Drupal\Core\Form\FormStateInterface $form_state: _id
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
File
- ./
simple_sitemap.module, line 40 - Main module file containing hooks.
Code
function simple_sitemap_form_alter(&$form, FormStateInterface $form_state, $form_id) {
/** @var Drupal\simple_sitemap\Form\FormHelper $f */
$f = \Drupal::service('simple_sitemap.form_helper');
if (!$f
->processForm($form_state)) {
return;
}
$form['simple_sitemap'] = [
'#type' => 'details',
'#group' => isset($form['additional_settings']) ? 'additional_settings' : 'advanced',
'#title' => t('Simple XML Sitemap'),
'#description' => $f
->getEntityCategory() === 'instance' ? t('Settings for this entity can be overridden here.') : '',
'#weight' => 10,
];
// Only attach fieldset summary js to 'additional settings' vertical tabs.
if (isset($form['additional_settings'])) {
$form['#attached']['library'][] = 'simple_sitemap/fieldsetSummaries';
}
$f
->displayEntitySettings($form['simple_sitemap'])
->displayRegenerateNow($form['simple_sitemap']);
// Add submission handler.
if (isset($form['actions']['submit']['#submit'])) {
foreach (array_keys($form['actions']) as $action) {
if ($action !== 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') {
$form['actions'][$action]['#submit'][] = 'simple_sitemap_entity_form_submit';
}
}
}
else {
$form['#submit'][] = 'simple_sitemap_entity_form_submit';
}
}