Commit c05868fc authored by gbyte's avatar gbyte Committed by Pawel G

Issue #2684767 by Sam152: Update code to adhere to coding standards

parent 7c8fb5fe
...@@ -23,5 +23,5 @@ function simple_sitemap_drush_command() { ...@@ -23,5 +23,5 @@ function simple_sitemap_drush_command() {
*/ */
function drush_simple_sitemap_generate() { function drush_simple_sitemap_generate() {
$sitemap = \Drupal::service('simple_sitemap.generator'); $sitemap = \Drupal::service('simple_sitemap.generator');
$sitemap->generate_sitemap('drush'); $sitemap->generateSitemap('drush');
} }
...@@ -22,7 +22,7 @@ function simple_sitemap_requirements($phase) { ...@@ -22,7 +22,7 @@ function simple_sitemap_requirements($phase) {
switch($phase) { switch($phase) {
case 'runtime': case 'runtime':
$sitemap = \Drupal::service('simple_sitemap.generator'); $sitemap = \Drupal::service('simple_sitemap.generator');
$generated_ago = $sitemap->get_generated_ago(); $generated_ago = $sitemap->getGeneratedAgo();
if (!$generated_ago) { if (!$generated_ago) {
$value = t('Not available'); $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')); $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'));
...@@ -80,7 +80,7 @@ function simple_sitemap_schema() { ...@@ -80,7 +80,7 @@ function simple_sitemap_schema() {
*/ */
function simple_sitemap_install() { function simple_sitemap_install() {
$sitemap = \Drupal::service('simple_sitemap.generator'); $sitemap = \Drupal::service('simple_sitemap.generator');
$sitemap->generate_sitemap('backend'); $sitemap->generateSitemap('backend');
$base_url = $GLOBALS['base_url']; $base_url = $GLOBALS['base_url'];
drupal_set_message(t("You can now include content into the <a href='@sitemap_url' target='_blank'>XML sitemap</a> by visiting the corresponding entity type edit pages (e.g. <a href='@content_type_url' target='_blank'>content type</a>, <a href='@taxonomy_vocabulary_url' target='_blank'>taxonomy vocabulary</a>, <a href='@menu_url' target='_blank'>menu</a> and <a href='@user_url' target='_blank'>user</a> pages.)<br/>Custom links can be added on <a href='@config_url' target='_blank'>this configuration page</a>.", array('@sitemap_url' => "$base_url/sitemap.xml", '@content_type_url' => "$base_url/admin/structure/types", '@taxonomy_vocabulary_url' => "$base_url/admin/structure/taxonomy", '@menu_url' => "$base_url/admin/structure/menu", '@user_url' => "$base_url/admin/config/people/accounts", '@config_url' => "$base_url/admin/config/search/simplesitemap/custom"))); drupal_set_message(t("You can now include content into the <a href='@sitemap_url' target='_blank'>XML sitemap</a> by visiting the corresponding entity type edit pages (e.g. <a href='@content_type_url' target='_blank'>content type</a>, <a href='@taxonomy_vocabulary_url' target='_blank'>taxonomy vocabulary</a>, <a href='@menu_url' target='_blank'>menu</a> and <a href='@user_url' target='_blank'>user</a> pages.)<br/>Custom links can be added on <a href='@config_url' target='_blank'>this configuration page</a>.", array('@sitemap_url' => "$base_url/sitemap.xml", '@content_type_url' => "$base_url/admin/structure/types", '@taxonomy_vocabulary_url' => "$base_url/admin/structure/taxonomy", '@menu_url' => "$base_url/admin/structure/menu", '@user_url' => "$base_url/admin/config/people/accounts", '@config_url' => "$base_url/admin/config/search/simplesitemap/custom")));
} }
...@@ -21,7 +21,7 @@ function simple_sitemap_help($route_name, \Drupal\Core\Routing\RouteMatchInterfa ...@@ -21,7 +21,7 @@ function simple_sitemap_help($route_name, \Drupal\Core\Routing\RouteMatchInterfa
* Adds sitemap settings to entity types that are supported via plugins. * Adds sitemap settings to entity types that are supported via plugins.
*/ */
function simple_sitemap_form_alter(&$form, $form_state, $form_id) { function simple_sitemap_form_alter(&$form, $form_state, $form_id) {
$sitemap_form_entity_data = Simplesitemap::get_sitemap_form_entity_data($form_state, $form_id); $sitemap_form_entity_data = Simplesitemap::getSitemapFormEntityData($form_state, $form_id);
if (empty($sitemap_form_entity_data)) if (empty($sitemap_form_entity_data))
return; return;
$entity_type_id = $sitemap_form_entity_data['entity_type_id']; $entity_type_id = $sitemap_form_entity_data['entity_type_id'];
...@@ -30,7 +30,7 @@ function simple_sitemap_form_alter(&$form, $form_state, $form_id) { ...@@ -30,7 +30,7 @@ function simple_sitemap_form_alter(&$form, $form_state, $form_id) {
$sitemap = \Drupal::service('simple_sitemap.generator'); $sitemap = \Drupal::service('simple_sitemap.generator');
// Get current entity type sitemap settings. // Get current entity type sitemap settings.
$entity_types = $sitemap->get_config('entity_types'); $entity_types = $sitemap->getConfig('entity_types');
$form['simple_sitemap'] = array( $form['simple_sitemap'] = array(
'#type' => 'details', '#type' => 'details',
...@@ -57,7 +57,7 @@ function simple_sitemap_form_alter(&$form, $form_state, $form_id) { ...@@ -57,7 +57,7 @@ function simple_sitemap_form_alter(&$form, $form_state, $form_id) {
'#type' => 'select', '#type' => 'select',
'#title' => t('Priority'), '#title' => t('Priority'),
'#description' => t('The priority entities of this bundle will have in the eyes of search engine bots.'), '#description' => t('The priority entities of this bundle will have in the eyes of search engine bots.'),
'#options' => SitemapGenerator::get_priority_select_values(), '#options' => SitemapGenerator::getPrioritySelectValues(),
'#default_value' => $priority, '#default_value' => $priority,
); );
...@@ -67,7 +67,7 @@ function simple_sitemap_form_alter(&$form, $form_state, $form_id) { ...@@ -67,7 +67,7 @@ function simple_sitemap_form_alter(&$form, $form_state, $form_id) {
'#description' => t('This setting will regenerate the whole sitemap including the above changes.'), '#description' => t('This setting will regenerate the whole sitemap including the above changes.'),
'#default_value' => FALSE, '#default_value' => FALSE,
); );
if ($sitemap->get_setting('cron_generate')) { if ($sitemap->getSetting('cron_generate')) {
$form['simple_sitemap']['simple_sitemap_regenerate_now']['#description'] .= '</br>' . t('Otherwise the sitemap will be rebuilt on next cron run.'); $form['simple_sitemap']['simple_sitemap_regenerate_now']['#description'] .= '</br>' . t('Otherwise the sitemap will be rebuilt on next cron run.');
} }
...@@ -99,18 +99,18 @@ function simple_sitemap_entity_form_submit($form, &$form_state) { ...@@ -99,18 +99,18 @@ function simple_sitemap_entity_form_submit($form, &$form_state) {
$bundle_name = $form['#simple_sitemap']['bundle_name']; $bundle_name = $form['#simple_sitemap']['bundle_name'];
// Get current entity type sitemap settings. // Get current entity type sitemap settings.
$entity_types = $sitemap->get_config('entity_types'); $entity_types = $sitemap->getConfig('entity_types');
$entity_types[$entity_type_id][$bundle_name]['index'] = $values['simple_sitemap_index_content']; $entity_types[$entity_type_id][$bundle_name]['index'] = $values['simple_sitemap_index_content'];
$entity_types[$entity_type_id][$bundle_name]['priority'] = $values['simple_sitemap_priority']; $entity_types[$entity_type_id][$bundle_name]['priority'] = $values['simple_sitemap_priority'];
// Save new entity type settings. // Save new entity type settings.
$sitemap->save_config('entity_types', $entity_types); $sitemap->saveConfig('entity_types', $entity_types);
} }
// Regenerate sitemaps according to user setting. // Regenerate sitemaps according to user setting.
if ($values['simple_sitemap_regenerate_now']) { if ($values['simple_sitemap_regenerate_now']) {
$sitemap->generate_sitemap(); $sitemap->generateSitemap();
} }
} }
...@@ -119,9 +119,9 @@ function simple_sitemap_entity_form_submit($form, &$form_state) { ...@@ -119,9 +119,9 @@ function simple_sitemap_entity_form_submit($form, &$form_state) {
*/ */
function simple_sitemap_cron() { function simple_sitemap_cron() {
$sitemap = \Drupal::service('simple_sitemap.generator'); $sitemap = \Drupal::service('simple_sitemap.generator');
if ($sitemap->get_setting('cron_generate')) { if ($sitemap->getSetting('cron_generate')) {
// Regenerate sitemap for all languages. // Regenerate sitemap for all languages.
$sitemap->generate_sitemap('backend'); $sitemap->generateSitemap('backend');
} }
} }
...@@ -132,14 +132,14 @@ function simple_sitemap_cron() { ...@@ -132,14 +132,14 @@ function simple_sitemap_cron() {
*/ */
function simple_sitemap_entity_bundle_delete($entity_type_id, $bundle) { function simple_sitemap_entity_bundle_delete($entity_type_id, $bundle) {
$sitemap = \Drupal::service('simple_sitemap.generator'); $sitemap = \Drupal::service('simple_sitemap.generator');
$entity_types = $sitemap->get_config('entity_types'); $entity_types = $sitemap->getConfig('entity_types');
$bundle_entity_type_id = \Drupal::entityManager()->getDefinition($entity_type_id)->getBundleEntityType(); $bundle_entity_type_id = \Drupal::entityManager()->getDefinition($entity_type_id)->getBundleEntityType();
if (isset($entity_types[$bundle_entity_type_id][$bundle])) { if (isset($entity_types[$bundle_entity_type_id][$bundle])) {
unset($entity_types[$bundle_entity_type_id][$bundle]); unset($entity_types[$bundle_entity_type_id][$bundle]);
$sitemap->save_config('entity_types', $entity_types); $sitemap->saveConfig('entity_types', $entity_types);
$message = t("You may want to <a href='@url'>regenerate</a> your XML sitemap now.", array('@url' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap')); $message = t("You may want to <a href='@url'>regenerate</a> your XML sitemap now.", array('@url' => $GLOBALS['base_url'] . '/admin/config/search/simplesitemap'));
if ($sitemap->get_setting('cron_generate')) { if ($sitemap->getSetting('cron_generate')) {
$message .= '</br>' . t('Otherwise the sitemap will be rebuilt on next cron run.'); $message .= '</br>' . t('Otherwise the sitemap will be rebuilt on next cron run.');
} }
drupal_set_message($message); drupal_set_message($message);
......
simple_sitemap.sitemap: simple_sitemap.sitemap:
path: '/sitemap.xml' path: '/sitemap.xml'
defaults: defaults:
_controller: '\Drupal\simple_sitemap\Controller\SimplesitemapController::get_sitemap' _controller: '\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
requirements: requirements:
_access: 'TRUE' _access: 'TRUE'
simple_sitemap.chunk: simple_sitemap.chunk:
path: '/sitemaps/{sitemap_id}/sitemap.xml' path: '/sitemaps/{sitemap_id}/sitemap.xml'
defaults: defaults:
_controller: '\Drupal\simple_sitemap\Controller\SimplesitemapController::get_sitemap' _controller: '\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
requirements: requirements:
_access: 'TRUE' _access: 'TRUE'
......
...@@ -16,7 +16,7 @@ use Drupal\Component\Utility\Html; ...@@ -16,7 +16,7 @@ use Drupal\Component\Utility\Html;
class Batch { class Batch {
private $batch; private $batch;
private $batch_info; private $batchInfo;
const PLUGIN_ERROR_MESSAGE = "The simple_sitemap @plugin plugin has been omitted, as it does not return the required numeric array of path data sets. Each data sets must contain the required path element (relative path string or Drupal\\Core\\Url object) and optionally other elements, like lastmod."; const PLUGIN_ERROR_MESSAGE = "The simple_sitemap @plugin plugin has been omitted, as it does not return the required numeric array of path data sets. Each data sets must contain the required path element (relative path string or Drupal\\Core\\Url object) and optionally other elements, like lastmod.";
const PATH_DOES_NOT_EXIST = "The path @faulty_path has been omitted from the XML sitemap, as it does not exist."; const PATH_DOES_NOT_EXIST = "The path @faulty_path has been omitted from the XML sitemap, as it does not exist.";
...@@ -31,10 +31,10 @@ class Batch { ...@@ -31,10 +31,10 @@ class Batch {
'error_message' => t('An error occurred'), 'error_message' => t('An error occurred'),
'progress_message' => t('Processing @current out of @total link types.'), 'progress_message' => t('Processing @current out of @total link types.'),
'operations' => array(), 'operations' => array(),
'finished' => __CLASS__ . '::finish_batch', 'finished' => __CLASS__ . '::finishBatch',
); );
$config = \Drupal::config('simple_sitemap.settings')->get('settings'); $config = \Drupal::config('simple_sitemap.settings')->get('settings');
$this->batch_info = array( $this->batchInfo = array(
'from' => $from, 'from' => $from,
'batch_process_limit' => $config['batch_process_limit'], 'batch_process_limit' => $config['batch_process_limit'],
'max_links' => $config['max_links'], 'max_links' => $config['max_links'],
...@@ -48,7 +48,7 @@ class Batch { ...@@ -48,7 +48,7 @@ class Batch {
*/ */
public function start() { public function start() {
batch_set($this->batch); batch_set($this->batch);
switch ($this->batch_info['from']) { switch ($this->batchInfo['from']) {
case 'form': case 'form':
break; break;
case 'drush': case 'drush':
...@@ -71,20 +71,20 @@ class Batch { ...@@ -71,20 +71,20 @@ class Batch {
* @param string $type * @param string $type
* @param array $operations * @param array $operations
*/ */
public function add_operations($type, $operations) { public function addOperations($type, $operations) {
switch ($type) { switch ($type) {
case 'entity_types': case 'entity_types':
foreach ($operations as $operation) { foreach ($operations as $operation) {
$this->batch['operations'][] = array( $this->batch['operations'][] = array(
__CLASS__ . '::generate_bundle_urls', __CLASS__ . '::generateBundleUrls',
array($operation['query'], $operation['info'], $this->batch_info) array($operation['query'], $operation['info'], $this->batchInfo)
); );
}; };
break; break;
case 'custom_paths': case 'custom_paths':
$this->batch['operations'][] = array( $this->batch['operations'][] = array(
__CLASS__ . '::generate_custom_urls', __CLASS__ . '::generateCustomUrls',
array($operations, $this->batch_info) array($operations, $this->batchInfo)
); );
break; break;
} }
...@@ -95,10 +95,10 @@ class Batch { ...@@ -95,10 +95,10 @@ class Batch {
* *
* @see https://api.drupal.org/api/drupal/core!includes!form.inc/group/batch/8 * @see https://api.drupal.org/api/drupal/core!includes!form.inc/group/batch/8
*/ */
public static function finish_batch($success, $results, $operations) { public static function finishBatch($success, $results, $operations) {
if ($success) { if ($success) {
if (!empty($results) || is_null(db_query('SELECT MAX(id) FROM {simple_sitemap}')->fetchField())) { if (!empty($results) || is_null(db_query('SELECT MAX(id) FROM {simple_sitemap}')->fetchField())) {
SitemapGenerator::generate_sitemap($results['generate']); SitemapGenerator::generateSitemap($results['generate']);
} }
drupal_set_message(t("The <a href='@url' target='_blank'>XML sitemap</a> has been regenerated for all languages.", drupal_set_message(t("The <a href='@url' target='_blank'>XML sitemap</a> has been regenerated for all languages.",
array('@url' => $GLOBALS['base_url'] . '/sitemap.xml'))); array('@url' => $GLOBALS['base_url'] . '/sitemap.xml')));
...@@ -117,13 +117,13 @@ class Batch { ...@@ -117,13 +117,13 @@ class Batch {
* *
* @see https://api.drupal.org/api/drupal/core!includes!form.inc/group/batch/8 * @see https://api.drupal.org/api/drupal/core!includes!form.inc/group/batch/8
*/ */
public static function generate_bundle_urls($query, $info, $batch_info, &$context) { public static function generateBundleUrls($query, $info, $batch_info, &$context) {
$languages = \Drupal::languageManager()->getLanguages(); $languages = \Drupal::languageManager()->getLanguages();
$default_language_id = Simplesitemap::get_default_lang_id(); $default_language_id = Simplesitemap::getDefaultLangId();
// Initializing batch. // Initializing batch.
if (empty($context['sandbox'])) { if (empty($context['sandbox'])) {
self::initialize_batch($query->countQuery()->execute()->fetchField(), $context); self::InitializeBatch($query->countQuery()->execute()->fetchField(), $context);
} }
// Getting id field name from plugin info, if not defined assuming the name of the first field in the query to be the entity id field name. // Getting id field name from plugin info, if not defined assuming the name of the first field in the query to be the entity id field name.
...@@ -154,7 +154,7 @@ class Batch { ...@@ -154,7 +154,7 @@ class Batch {
$result = $query->execute()->fetchAll(); $result = $query->execute()->fetchAll();
foreach ($result as $row) { foreach ($result as $row) {
self::set_current_id($row->$id_field, $context); self::SetCurrentId($row->$id_field, $context);
// Setting route parameters if they exist in the database (menu links). // Setting route parameters if they exist in the database (menu links).
if (isset($route_params_field) && !empty($route_parameters = unserialize($row->$route_params_field))) { if (isset($route_params_field) && !empty($route_parameters = unserialize($row->$route_params_field))) {
...@@ -194,7 +194,7 @@ class Batch { ...@@ -194,7 +194,7 @@ class Batch {
// Do not include path if it already exists. // Do not include path if it already exists.
$path = $url_object->getInternalPath(); $path = $url_object->getInternalPath();
if ($batch_info['remove_duplicates'] && self::path_processed($path, $context['results']['processed_paths'])) if ($batch_info['remove_duplicates'] && self::batchProcessed($path, $context['results']['processed_paths']))
continue; continue;
$urls = array(); $urls = array();
...@@ -216,8 +216,8 @@ class Batch { ...@@ -216,8 +216,8 @@ class Batch {
'priority' => !empty($info['bundle_settings']['priority']) ? $info['bundle_settings']['priority'] : NULL, 'priority' => !empty($info['bundle_settings']['priority']) ? $info['bundle_settings']['priority'] : NULL,
); );
} }
self::set_progress_info($context, $batch_info); self::setProgressInfo($context, $batch_info);
self::process_segment($context, $batch_info); self::processSegment($context, $batch_info);
} }
/** /**
...@@ -229,22 +229,22 @@ class Batch { ...@@ -229,22 +229,22 @@ class Batch {
* *
* @see https://api.drupal.org/api/drupal/core!includes!form.inc/group/batch/8 * @see https://api.drupal.org/api/drupal/core!includes!form.inc/group/batch/8
*/ */
public static function generate_custom_urls($custom_paths, $batch_info, &$context) { public static function generateCustomUrls($custom_paths, $batch_info, &$context) {
$languages = \Drupal::languageManager()->getLanguages(); $languages = \Drupal::languageManager()->getLanguages();
$default_language_id = Simplesitemap::get_default_lang_id(); $default_language_id = Simplesitemap::getDefaultLangId();
// Initializing batch. // Initializing batch.
if (empty($context['sandbox'])) { if (empty($context['sandbox'])) {
self::initialize_batch(count($custom_paths), $context); self::InitializeBatch(count($custom_paths), $context);
} }
foreach($custom_paths as $i => $custom_path) { foreach($custom_paths as $i => $custom_path) {
self::set_current_id($i, $context); self::SetCurrentId($i, $context);
$user_input = $custom_path['path'][0] === '/' ? $custom_path['path'] : '/' . $custom_path['path']; $user_input = $custom_path['path'][0] === '/' ? $custom_path['path'] : '/' . $custom_path['path'];
if (!\Drupal::service('path.validator')->isValid($custom_path['path'])) { //todo: Change to different function, as this also checks if current user has access. The user however varies depending if process was started from the web interface or via cron/drush. if (!\Drupal::service('path.validator')->isValid($custom_path['path'])) { //todo: Change to different function, as this also checks if current user has access. The user however varies depending if process was started from the web interface or via cron/drush.
self::register_error(self::PATH_DOES_NOT_EXIST_OR_NO_ACCESS, array('@faulty_path' => $custom_path['path']), 'warning'); self::registerError(self::PATH_DOES_NOT_EXIST_OR_NO_ACCESS, array('@faulty_path' => $custom_path['path']), 'warning');
continue; continue;
} }
$options = array('absolute' => TRUE, 'language' => $languages[$default_language_id]); $options = array('absolute' => TRUE, 'language' => $languages[$default_language_id]);
...@@ -254,7 +254,7 @@ class Batch { ...@@ -254,7 +254,7 @@ class Batch {
continue; continue;
$path = $url_object->getInternalPath(); $path = $url_object->getInternalPath();
if ($batch_info['remove_duplicates'] && self::path_processed($path, $context['results']['processed_paths'])) if ($batch_info['remove_duplicates'] && self::batchProcessed($path, $context['results']['processed_paths']))
continue; continue;
$urls = array(); $urls = array();
...@@ -275,11 +275,11 @@ class Batch { ...@@ -275,11 +275,11 @@ class Batch {
'priority' => !empty($custom_path['priority']) ? $custom_path['priority'] : NULL, 'priority' => !empty($custom_path['priority']) ? $custom_path['priority'] : NULL,
); );
} }
self::set_progress_info($context, $batch_info); self::setProgressInfo($context, $batch_info);
self::process_segment($context, $batch_info); self::processSegment($context, $batch_info);
} }
private static function path_processed($needle, &$path_pool) { private static function batchProcessed($needle, &$path_pool) {
if (in_array($needle, $path_pool)) { if (in_array($needle, $path_pool)) {
return TRUE; return TRUE;
} }
...@@ -287,7 +287,7 @@ class Batch { ...@@ -287,7 +287,7 @@ class Batch {
return FALSE; return FALSE;
} }
private static function initialize_batch($max, &$context) { private static function InitializeBatch($max, &$context) {
$context['sandbox']['progress'] = 0; $context['sandbox']['progress'] = 0;
$context['sandbox']['current_id'] = 0; $context['sandbox']['current_id'] = 0;
$context['sandbox']['max'] = $max; $context['sandbox']['max'] = $max;
...@@ -295,13 +295,13 @@ class Batch { ...@@ -295,13 +295,13 @@ class Batch {
$context['results']['processed_paths'] = !empty($context['results']['processed_paths']) ? $context['results']['processed_paths'] : array(); $context['results']['processed_paths'] = !empty($context['results']['processed_paths']) ? $context['results']['processed_paths'] : array();
} }
private static function set_current_id($id, &$context) { private static function SetCurrentId($id, &$context) {
$context['sandbox']['progress']++; $context['sandbox']['progress']++;
$context['sandbox']['current_id'] = $id; $context['sandbox']['current_id'] = $id;
} }
private static function set_progress_info(&$context, $batch_info) { private static function setProgressInfo(&$context, $batch_info) {
if ($context['sandbox']['progress'] != $context['sandbox']['max']) { if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
// Providing progress info to the batch API. // Providing progress info to the batch API.
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
...@@ -318,12 +318,12 @@ class Batch { ...@@ -318,12 +318,12 @@ class Batch {
} }
} }
private static function process_segment(&$context, $batch_info) { private static function processSegment(&$context, $batch_info) {
if (!empty($batch_info['max_links']) && count($context['results']['generate']) >= $batch_info['max_links']) { if (!empty($batch_info['max_links']) && count($context['results']['generate']) >= $batch_info['max_links']) {
$chunks = array_chunk($context['results']['generate'], $batch_info['max_links']); $chunks = array_chunk($context['results']['generate'], $batch_info['max_links']);
foreach ($chunks as $i => $chunk_links) { foreach ($chunks as $i => $chunk_links) {
if (count($chunk_links) == $batch_info['max_links']) { if (count($chunk_links) == $batch_info['max_links']) {
SitemapGenerator::generate_sitemap($chunk_links); SitemapGenerator::generateSitemap($chunk_links);
$context['results']['generate'] = array_slice($context['results']['generate'], count($chunk_links)); $context['results']['generate'] = array_slice($context['results']['generate'], count($chunk_links));
} }
} }
...@@ -341,7 +341,7 @@ class Batch { ...@@ -341,7 +341,7 @@ class Batch {
* @param string $type (optional) * @param string $type (optional)
* Message type (status/warning/error). * Message type (status/warning/error).
*/ */
private static function register_error($message, $substitutions = array(), $type = 'error') { private static function registerError($message, $substitutions = array(), $type = 'error') {
$message = strtr(t($message), $substitutions); $message = strtr(t($message), $substitutions);
\Drupal::logger('simple_sitemap')->notice($message); \Drupal::logger('simple_sitemap')->notice($message);
drupal_set_message($message, $type); drupal_set_message($message, $type);
......
...@@ -24,9 +24,9 @@ class SimplesitemapController { ...@@ -24,9 +24,9 @@ class SimplesitemapController {
* @return object Response * @return object Response
* Returns an XML response. * Returns an XML response.
*/ */
public function get_sitemap($sitemap_id = NULL) { public function getSitemap($sitemap_id = NULL) {
$sitemap = \Drupal::service('simple_sitemap.generator'); $sitemap = \Drupal::service('simple_sitemap.generator');
$output = $sitemap->get_sitemap($sitemap_id); $output = $sitemap->getSitemap($sitemap_id);
$output = !$output ? '' : $output; $output = !$output ? '' : $output;
// Display sitemap with correct xml header. // Display sitemap with correct xml header.
......
...@@ -21,7 +21,7 @@ class CustomLinkGenerator { ...@@ -21,7 +21,7 @@ class CustomLinkGenerator {
* @return array $urls * @return array $urls
* *
*/ */
public function get_custom_paths($custom_paths) { public function getCustomPaths($custom_paths) {
$paths = array(); $paths = array();
foreach($custom_paths as $i => $custom_path) { foreach($custom_paths as $i => $custom_path) {
$paths[$i]['path'] = $custom_path['path']; $paths[$i]['path'] = $custom_path['path'];
......
...@@ -36,7 +36,7 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase { ...@@ -36,7 +36,7 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
$sitemap = \Drupal::service('simple_sitemap.generator'); $sitemap = \Drupal::service('simple_sitemap.generator');
$setting_string = ''; $setting_string = '';
foreach ($sitemap->get_config('custom') as $custom_link) { foreach ($sitemap->getConfig('custom') as $custom_link) {
// todo: remove this statement after removing the index key from the configuration. // todo: remove this statement after removing the index key from the configuration.
if (isset($custom_link['index']) && $custom_link['index'] == 0) if (isset($custom_link['index']) && $custom_link['index'] == 0)
...@@ -65,7 +65,7 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase { ...@@ -65,7 +65,7 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
'#description' => t('This setting will regenerate the whole sitemap including the above changes.'), '#description' => t('This setting will regenerate the whole sitemap including the above changes.'),
'#default_value' => FALSE, '#default_value' => FALSE,
); );
if ($sitemap->get_setting('cron_generate')) { if ($sitemap->getSetting('cron_generate')) {
$form['simple_sitemap_custom']['simple_sitemap_regenerate_now']['#description'] .= '</br>' . t('Otherwise the sitemap will be rebuilt on next cron run.'); $form['simple_sitemap_custom']['simple_sitemap_regenerate_now']['#description'] .= '</br>' . t('Otherwise the sitemap will be rebuilt on next cron run.');
} }
...@@ -77,7 +77,7 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase { ...@@ -77,7 +77,7 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
*/ */
public function validateForm(array &$form, FormStateInterface $form_state) { public function validateForm(array &$form, FormStateInterface $form_state) {
$custom_link_config = $this->get_custom_links($form_state->getValue('custom_links')); $custom_link_config = $this->getCustomLinks($form_state->getValue('custom_links'));
foreach($custom_link_config as $link_config) { foreach($custom_link_config as $link_config) {
...@@ -100,22 +100,22 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase { ...@@ -100,22 +100,22 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
*/ */
public function submitForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) {
$sitemap = \Drupal::service('simple_sitemap.generator'); $sitemap = \Drupal::service('simple_sitemap.generator');
$custom_link_config = $this->get_custom_links($form_state->getValue('custom_links')); $custom_link_config = $this->getCustomLinks($form_state->getValue('custom_links'));
foreach($custom_link_config as &$link_config) { foreach($custom_link_config as &$link_config) {
if (isset($link_config['priority'])) { if (isset($link_config['priority'])) {
$link_config['priority'] = number_format((float)$link_config['priority'], 1, '.', ''); $link_config['priority'] = number_format((float)$link_config['priority'], 1, '.', '');
} }
} }
$sitemap->save_config('custom', $custom_link_config); $sitemap->saveConfig('custom', $custom_link_config);
parent::submitForm($form, $form_state); parent::submitForm($form, $form_state);
// Regenerate sitemaps according to user setting. // Regenerate sitemaps according to user setting.
if ($form_state->getValue('simple_sitemap_regenerate_now')) { if ($form_state->getValue('simple_sitemap_regenerate_now')) {
$sitemap->generate_sitemap(); $sitemap->generateSitemap();
} }
} }
private function get_custom_links($custom_links_string) { private function getCustomLinks($custom_links_string) {
$custom_links_string_lines = array_filter(explode("\n", str_replace("\r\n", "\n", $custom_links_string)), 'trim'); $custom_links_string_lines = array_filter(explode("\n", str_replace("\r\n", "\n", $custom_links_string)), 'trim');
$custom_link_config = array(); $custom_link_config = array();
foreach($custom_links_string_lines as $i => $line) { foreach($custom_links_string_lines as $i => $line) {
......
...@@ -47,7 +47,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase { ...@@ -47,7 +47,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
$form['simple_sitemap_settings']['regenerate']['regenerate_submit'] = array( $form['simple_sitemap_settings']['regenerate']['regenerate_submit'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Regenerate sitemap'),