Commit 9d6ed0e8 authored by gbyte.co's avatar gbyte.co

Adding 'rebuild sitemap button' on configuration page, altering configuration...

Adding 'rebuild sitemap button' on configuration page, altering configuration during deletion of bundles.
parent e9461601
......@@ -10,7 +10,7 @@ use Drupal\simplesitemap\SitemapGenerator;
/**
* Implements hook_form_alter.
*/
function simplesitemap_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
function simplesitemap_form_alter(&$form, $form_state, $form_id) {
$form_entity = Simplesitemap::get_form_entity($form_state);
if (!$form_entity)
......@@ -104,3 +104,18 @@ function simplesitemap_cron() {
$sitemap->generate_sitemap();
}
/**
* Implements hook_entity_bundle_delete().
*/
function simplesitemap_entity_bundle_delete($entity_type_id, $bundle) {
$sitemap = new Simplesitemap;
$entity_types = $sitemap->get_entity_types();
$bundle_entity_type_id = \Drupal::entityManager()->getDefinition($entity_type_id)->getBundleEntityType();
if (isset($entity_types[$bundle_entity_type_id][$bundle])) {
unset($entity_types[$bundle_entity_type_id][$bundle]);
$sitemap->save_entity_types($entity_types);
drupal_set_message(t("You may want to <a href='@url'>rebuild</a> your XML sitemap now. Otherwise it will be rebuilt on the next cron run.", array('@url' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap')));
}
}
......@@ -49,14 +49,15 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
$form['simplesitemap_custom'] = array(
'#title' => t('Custom links'),
'#type' => 'fieldset',
'#markup' => '<p>' . t('Add custom internal drupal paths and their priorities to the XML sitemap.') . '</p>',
);
$form['simplesitemap_custom']['custom_links'] = array(
'#type' => 'textarea',
'#title' => '<span class="element-invisibule">' . t('Relative Drupal paths') . '</span>',
'#title' => t('Relative Drupal paths'),
'#default_value' => $setting_string,
'#prefix' => t('Add custom internal drupal paths to the XML sitemap and specify their priorities.'),
'#description' => t("Please specify drupal internal (relative) paths, one per line. Do not forget to prepend the paths with an '/' You can add a priority (0.0 - 1.0) by appending it to the path after a space. The home page with the highest priority would be <em>/ 1</em>, the contact page with a medium priority would be <em>/contact 0.5</em>."),
'#description' => t("Please specify drupal internal (relative) paths, one per line. Do not forget to prepend the paths with a '/' You can optionally add a priority (0.0 - 1.0) by appending it to the path after a space. The home page with the highest priority would be <em>/ 1</em>, the contact page with a medium priority would be <em>/contact 0.5</em>."),
);
$form['simplesitemap_custom']['simplesitemap_rebuild_now'] = array(
......
......@@ -9,6 +9,7 @@ namespace Drupal\simplesitemap\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\simplesitemap\Simplesitemap;
/**
* SimplesitemapSettingsFrom
......@@ -33,23 +34,25 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['simplesitemap_custom'] = array(
$form['simplesitemap_settings']['rebuild'] = array(
'#title' => t('Rebuild sitemap'),
'#type' => 'fieldset',
'#title' => t('No settings'),
'#description' => t('There are no settings here yet. Visit the other tab.'),
'#markup' => '<p>' . t('This will rebuild the XML sitemap for all languages.') . '</p>',
);
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$form['simplesitemap_settings']['rebuild']['rebuild_submit'] = array(
'#type' => 'submit',
'#value' => t('Rebuild sitemap'),
'#submit' => array('::rebuild_sitemap'),
'#validate' => array(), // Skip form-level validator.
);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
public function rebuild_sitemap(array &$form, FormStateInterface $form_state) {
$sitemap = new Simplesitemap;
$sitemap->generate_sitemap();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment