Commit 31337932 authored by gbyte.co's avatar gbyte.co Committed by gbyte.co

Adding PHP requirement checking and status messages on /admin/reports/status.

parent f20f6256
......@@ -4,6 +4,46 @@
* Module install and update procedures.
*/
/**
* Implements hook_requirements().
*/
function simplesitemap_requirements($phase) {
$requirements = array();
if (!extension_loaded('xmlwriter')) {
$requirements['simplesitemap_php_extensions'] = array(
'title' => t('Simple XML sitemap PHP extensions'),
'value' => t('Missing PHP xmlwriter extension'),
'description' => t("In order to be able to generate sitemaps, the Simple XML sitemap module requires the <em>xmlwriter</em> PHP extension to be enabled."),
'severity' => REQUIREMENT_ERROR,
);
}
switch($phase) {
case 'runtime':
$sitemap = new \Drupal\simplesitemap\Simplesitemap();
$generated_ago = $sitemap->get_generated_ago();
if (!$generated_ago) {
$value = t('Not available');
$description = t("The sitemap has not been generated yet. Run cron, or <a href='@generate'>generate</a> the sitemap manually.", array('@generate' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap'));
$severity = REQUIREMENT_WARNING;
}
else {
$value = t('XML sitemap is available');
$description = t("The <a href='@sitemap'>XML sitemap</a> was generated @ago ago. <a href='@generate'>Regenerate</a>.", array('@ago' => $generated_ago, '@sitemap' => $GLOBALS['base_url'] . '/sitemap.xml', '@generate' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap'));
$severity = REQUIREMENT_INFO;
}
$requirements['simplesitemap_generated'] = array(
'title' => 'Simple XML sitemap',
'value' => $value,
'description' => $description,
'severity' => $severity,
);
break;
}
return $requirements;
}
/**
* Implements hook_schema().
*/
......
# This is the link to GeshiFilter settings in admin/config.
simplesitemap.settings:
title: 'Simple XML sitemap'
description: 'Configure and rebuild the XML sitemap, add custom links to it.'
description: 'Configure and generate the XML sitemap, add custom links to it.'
parent: system.admin_config_search
route_name: simplesitemap.settings
......@@ -77,10 +77,10 @@ function simplesitemap_form_alter(&$form, $form_state, $form_id) {
'#default_value' => $priority,
);
$form['simplesitemap']['simplesitemap_rebuild_now'] = array(
$form['simplesitemap']['simplesitemap_regenerate_now'] = array(
'#type' => 'checkbox',
'#title' => t('Rebuild sitemap after hitting Save'),
'#description' => t('This setting will rebuild the whole sitemap including the above changes.<br/>Otherwise the sitemap will be rebuilt on next cron run.'),
'#title' => t('Regenerate sitemap after hitting Save'),
'#description' => t('This setting will regenerate the whole sitemap including the above changes.<br/>Otherwise the sitemap will be rebuilt on next cron run.'),
'#default_value' => FALSE,
);
......@@ -118,7 +118,7 @@ function simplesitemap_entity_form_submit($form, &$form_state) {
}
// Regenerate sitemaps according to user setting.
if ($values['simplesitemap_rebuild_now']) {
if ($values['simplesitemap_regenerate_now']) {
$sitemap->generate_sitemap();
}
}
......@@ -147,7 +147,7 @@ function simplesitemap_entity_bundle_delete($entity_type_id, $bundle) {
if (isset($entity_types[$bundle_entity_type_id][$bundle])) {
unset($entity_types[$bundle_entity_type_id][$bundle]);
$sitemap->save_config('entity_types', $entity_types);
drupal_set_message(t("You may want to <a href='@url'>rebuild</a> your XML sitemap now.
drupal_set_message(t("You may want to <a href='@url'>regenerate</a> your XML sitemap now.
Otherwise it will be rebuilt on the next cron run.",
array('@url' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap')));
}
......
......@@ -60,10 +60,10 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
'#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(
$form['simplesitemap_custom']['simplesitemap_regenerate_now'] = array(
'#type' => 'checkbox',
'#title' => t('Rebuild sitemap after hitting Save'),
'#description' => t('This setting will rebuild the whole sitemap including the above changes.<br/>Otherwise the sitemap will be rebuilt on next cron run.'),
'#title' => t('Regenerate sitemap after hitting Save'),
'#description' => t('This setting will regenerate the whole sitemap including the above changes.<br/>Otherwise the sitemap will be rebuilt on next cron run.'),
'#default_value' => FALSE,
);
......@@ -117,7 +117,7 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
parent::submitForm($form, $form_state);
// Regenerate sitemaps according to user setting.
if ($form_state->getValue('simplesitemap_rebuild_now')) {
if ($form_state->getValue('simplesitemap_regenerate_now')) {
$sitemap->generate_sitemap();
}
}
......
......@@ -37,16 +37,16 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
$sitemap = new Simplesitemap;
$form['simplesitemap_settings']['rebuild'] = array(
'#title' => t('Rebuild sitemap'),
$form['simplesitemap_settings']['regenerate'] = array(
'#title' => t('Regenerate sitemap'),
'#type' => 'fieldset',
'#markup' => '<p>' . t('This will rebuild the XML sitemap for all languages.') . '</p>',
'#markup' => '<p>' . t('This will regenerate the XML sitemap for all languages.') . '</p>',
);
$form['simplesitemap_settings']['rebuild']['rebuild_submit'] = array(
$form['simplesitemap_settings']['regenerate']['regenerate_submit'] = array(
'#type' => 'submit',
'#value' => t('Rebuild sitemap'),
'#submit' => array('::rebuild_sitemap'),
'#value' => t('Regenerate sitemap'),
'#submit' => array('::generate_sitemap'),
'#validate' => array(), // Skip form-level validator.
);
......@@ -97,7 +97,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
parent::submitForm($form, $form_state);
}
public function rebuild_sitemap(array &$form, FormStateInterface $form_state) {
public function generate_sitemap(array &$form, FormStateInterface $form_state) {
$sitemap = new Simplesitemap;
$sitemap->generate_sitemap();
}
......
......@@ -184,4 +184,12 @@ class Simplesitemap {
$settings[$name] = $setting;
$this->save_config('settings', $settings);
}
public function get_generated_ago() {
if (isset($this->sitemap[0]->sitemap_created)) {
return \Drupal::service('date.formatter')
->formatInterval(REQUEST_TIME - $this->sitemap[0]->sitemap_created);
}
return FALSE;
}
}
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