Commit 537a283b authored by andrei.dincu's avatar andrei.dincu

Issue #2249723 by andrei.dincu: Create Drupal\xmlsitemap\Form\XmlSitemapSettingsForm class

parent c5a1af03
<?php
/**
* @file
* Contains \Drupal\xmlsitemap\Form\XmlSitemapSettingsForm.
*/
namespace Drupal\xmlsitemap\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Component\Utility\MapArray;
use Drupal\Component\Utility\UrlHelper;
/**
* Configure xmlsitemap settings for this site.
*/
class XmlSitemapSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'xmlsitemap_admin_settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
global $base_root;
$intervals = array(300, 900, 1800, 3600, 10800, 21600, 43200, 86400, 172800, 259200, 604800);
$form['xmlsitemap_minimum_lifetime'] = array(
'#type' => 'select',
'#title' => t('Minimum sitemap lifetime'),
'#options' => array(0 => t('No minimum')) + array_map('format_interval', array_combine($intervals, $intervals)),
'#description' => t('The minimum amount of time that will elapse before the sitemaps are regenerated. The sitemaps will also only be regenerated on cron if any links have been added, updated, or deleted.') . '<br />' . t('Recommended value: %value.', array('%value' => t('1 day'))),
'#default_value' => \Drupal::config('xmlsitemap.settings')->get('minimum_lifetime'),
);
$form['xmlsitemap_xsl'] = array(
'#type' => 'checkbox',
'#title' => t('Include a stylesheet in the sitemaps for humans.'),
'#description' => t('When enabled, this will add formatting and tables with sorting to make it easier to view the XML sitemap data instead of viewing raw XML output. Search engines will ignore this.'),
'#default_value' => \Drupal::config('xmlsitemap.settings')->get('xsl'),
);
$form['xmlsitemap_prefetch_aliases'] = array(
'#type' => 'checkbox',
'#title' => t('Prefetch URL aliases during sitemap generation.'),
'#description' => t('When enabled, this will fetch all URL aliases at once instead of one at a time during sitemap generation. For medium or large sites, it is recommended to disable this feature as it uses a lot of memory.'),
'#default_value' => \Drupal::config('xmlsitemap.settings')->get('prefetch_aliases'),
);
$form['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced settings'),
'#collapsible' => TRUE,
'#collapsed' => !\Drupal::config('xmlsitemap.settings')->get('developer_mode'),
'#weight' => 10,
);
//$form['advanced']['xmlsitemap_gz'] = array(
// '#type' => 'checkbox',
// '#title' => t('Generate additional compressed sitemaps using gzip.'),
// '#default_value' => xmlsitemap_var('gz'),
// '#disabled' => !function_exists('gzencode'),
//);
$chunk_sizes = array(100, 500, 1000, 2500, 5000, 10000, 25000, XMLSITEMAP_MAX_SITEMAP_LINKS);
$form['advanced']['xmlsitemap_chunk_size'] = array(
'#type' => 'select',
'#title' => t('Number of links in each sitemap page'),
'#options' => array('auto' => t('Automatic (recommended)')) + array_combine($chunk_sizes, $chunk_sizes),
'#default_value' => xmlsitemap_var('chunk_size'),
// @todo This description is not clear.
'#description' => t('If there are problems with rebuilding the sitemap, you may want to manually set this value. If you have more than @max links, an index with multiple sitemap pages will be generated. There is a maximum of @max sitemap pages.', array('@max' => XMLSITEMAP_MAX_SITEMAP_LINKS)),
);
$batch_limits = array(5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000);
$form['advanced']['xmlsitemap_batch_limit'] = array(
'#type' => 'select',
'#title' => t('Maximum number of sitemap links to process at once'),
'#options' => array_combine($batch_limits, $batch_limits),
'#default_value' => xmlsitemap_var('batch_limit'),
'#description' => t('If you have problems running cron or rebuilding the sitemap, you may want to lower this value.'),
);
if (!xmlsitemap_check_directory()) {
form_set_error('xmlsitemap_path', t('The directory %directory does not exist or is not writable.', array('%directory' => xmlsitemap_get_directory())));
}
$form['advanced']['xmlsitemap_path'] = array(
'#type' => 'textfield',
'#title' => t('Sitemap cache directory'),
'#default_value' => \Drupal::config('xmlsitemap.settings')->get('path'),
'#size' => 30,
'#maxlength' => 255,
'#description' => t('Subdirectory where the sitemap data will be stored. This folder <strong>must not be shared</strong> with any other Drupal site or install using XML sitemap.'),
'#field_prefix' => file_build_uri(''),
'#required' => TRUE,
);
$form['advanced']['xmlsitemap_base_url'] = array(
'#type' => 'textfield',
'#title' => t('Default base URL'),
'#default_value' => \Drupal::config('xmlsitemap.settings')->get('base_url'),
'#size' => 30,
'#description' => t('This is the default base URL used for sitemaps and sitemap links.'),
'#required' => TRUE,
);
$form['advanced']['xmlsitemap_lastmod_format'] = array(
'#type' => 'select',
'#title' => t('Last modification date format'),
'#options' => array(
XMLSITEMAP_LASTMOD_SHORT => t('Short'),
XMLSITEMAP_LASTMOD_MEDIUM => t('Medium'),
XMLSITEMAP_LASTMOD_LONG => t('Long'),
),
'#default_value' => \Drupal::config('xmlsitemap.settings')->get('lastmod_format'),
);
foreach ($form['advanced']['xmlsitemap_lastmod_format']['#options'] as $key => &$label) {
$label .= ' (' . gmdate($key, REQUEST_TIME) . ')';
}
$form['advanced']['xmlsitemap_developer_mode'] = array(
'#type' => 'checkbox',
'#title' => t('Enable developer mode to expose additional settings.'),
'#default_value' => \Drupal::config('xmlsitemap.settings')->get('developer_mode'),
);
$form['xmlsitemap_settings'] = array(
'#type' => 'vertical_tabs',
'#weight' => 20,
);
//$entities = xmlsitemap_get_link_info(NULL, TRUE);
//module_load_all_includes('inc', 'xmlsitemap');
/* foreach ($entities as $entity => $entity_info) {
$form[$entity] = array(
'#type' => 'fieldset',
'#title' => $entity_info['label'],
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'xmlsitemap_settings',
);
if (!empty($entity_info['bundles'])) {
// If this entity has bundles, show a bundle setting summary.
xmlsitemap_add_form_entity_summary($form[$entity], $entity, $entity_info);
}
if (!empty($entity_info['xmlsitemap']['settings callback'])) {
// Add any entity-specific settings.
$entity_info['xmlsitemap']['settings callback']($form[$entity]);
}
// Ensure that the entity fieldset is not shown if there are no accessible
// sub-elements.
$form[$entity]['#access'] = (bool) element_get_visible_children($form[$entity]);
} */
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, array &$form_state) {
// Check that the chunk size will not create more than 1000 chunks.
$chunk_size = $form_state['values']['xmlsitemap_chunk_size'];
if ($chunk_size != 'auto' && $chunk_size != 50000 && (xmlsitemap_get_link_count() / $chunk_size) > 1000) {
form_set_error('xmlsitemap_chunk_size', t('The sitemap page link count of @size will create more than 1,000 sitemap pages. Please increase the link count.', array('@size' => $chunk_size)));
}
$base_url = &$form_state['values']['xmlsitemap_base_url'];
$base_url = rtrim($base_url, '/');
if ($base_url != '' && !UrlHelper::isValid($base_url, TRUE)) {
\Drupal::formBuilder()->setErrorByName('xmlsitemap_base_url', $form_state,t('Invalid base URL.'));
}
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
// Save any changes to the frontpage link.
xmlsitemap_link_save(array('type' => 'frontpage', 'id' => 0, 'loc' => ''));
parent::submitForm($form, $form_state);
}
}
......@@ -8,9 +8,10 @@
* @file
* Main file for the xmlsitemap module.
*/
use Symfony\Component\HttpFoundation\Request;
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Session\UserSession;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Language\LanguageInterface;
/**
* The maximum number of links in one sitemap chunk file.
......@@ -574,7 +575,7 @@ function xmlsitemap_link_save(array $link) {
'priority_override' => 0,
'changefreq' => 0,
'changecount' => 0,
'language' => LANGUAGE_NONE,
'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
);
// Allow other modules to alter the link before saving.
......
......@@ -242,8 +242,8 @@ function xmlsitemap_link_frontpage_settings(&$form) {
function xmlsitemap_xmlsitemap_link_alter(&$link) {
// Alter the frontpage priority.
if ($link['type'] == 'frontpage' || $link['loc'] == '' || $link['loc'] == variable_get('site_frontpage', 'node')) {
$link['priority'] = variable_get('xmlsitemap_frontpage_priority', 1.0);
$link['changefreq'] = variable_get('xmlsitemap_frontpage_changefreq', XMLSITEMAP_FREQUENCY_DAILY);
$link['priority'] = \Drupal::config('xmlsitemap.settings')->get('frontpage_priority');
$link['changefreq'] = \Drupal::config('xmlsitemap.settings')->get('frontpage_changefreq');
}
}
......
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