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

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

parent 7c8fb5fe
......@@ -23,5 +23,5 @@ function simple_sitemap_drush_command() {
*/
function drush_simple_sitemap_generate() {
$sitemap = \Drupal::service('simple_sitemap.generator');
$sitemap->generate_sitemap('drush');
$sitemap->generateSitemap('drush');
}
......@@ -22,7 +22,7 @@ function simple_sitemap_requirements($phase) {
switch($phase) {
case 'runtime':
$sitemap = \Drupal::service('simple_sitemap.generator');
$generated_ago = $sitemap->get_generated_ago();
$generated_ago = $sitemap->getGeneratedAgo();
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'));
......@@ -80,7 +80,7 @@ function simple_sitemap_schema() {
*/
function simple_sitemap_install() {
$sitemap = \Drupal::service('simple_sitemap.generator');
$sitemap->generate_sitemap('backend');
$sitemap->generateSitemap('backend');
$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")));
}
......@@ -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.
*/
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))
return;
$entity_type_id = $sitemap_form_entity_data['entity_type_id'];
......@@ -30,7 +30,7 @@ function simple_sitemap_form_alter(&$form, $form_state, $form_id) {
$sitemap = \Drupal::service('simple_sitemap.generator');
// Get current entity type sitemap settings.
$entity_types = $sitemap->get_config('entity_types');
$entity_types = $sitemap->getConfig('entity_types');
$form['simple_sitemap'] = array(
'#type' => 'details',
......@@ -57,7 +57,7 @@ function simple_sitemap_form_alter(&$form, $form_state, $form_id) {
'#type' => 'select',
'#title' => t('Priority'),
'#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,
);
......@@ -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.'),
'#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.');
}
......@@ -99,18 +99,18 @@ function simple_sitemap_entity_form_submit($form, &$form_state) {
$bundle_name = $form['#simple_sitemap']['bundle_name'];
// 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]['priority'] = $values['simple_sitemap_priority'];
// Save new entity type settings.
$sitemap->save_config('entity_types', $entity_types);
$sitemap->saveConfig('entity_types', $entity_types);
}
// Regenerate sitemaps according to user setting.
if ($values['simple_sitemap_regenerate_now']) {
$sitemap->generate_sitemap();
$sitemap->generateSitemap();
}
}
......@@ -119,9 +119,9 @@ function simple_sitemap_entity_form_submit($form, &$form_state) {
*/
function simple_sitemap_cron() {
$sitemap = \Drupal::service('simple_sitemap.generator');
if ($sitemap->get_setting('cron_generate')) {
if ($sitemap->getSetting('cron_generate')) {
// Regenerate sitemap for all languages.
$sitemap->generate_sitemap('backend');
$sitemap->generateSitemap('backend');
}
}
......@@ -132,14 +132,14 @@ function simple_sitemap_cron() {
*/
function simple_sitemap_entity_bundle_delete($entity_type_id, $bundle) {
$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();
if (isset($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'));
if ($sitemap->get_setting('cron_generate')) {
if ($sitemap->getSetting('cron_generate')) {
$message .= '</br>' . t('Otherwise the sitemap will be rebuilt on next cron run.');
}
drupal_set_message($message);
......
simple_sitemap.sitemap:
path: '/sitemap.xml'
defaults:
_controller: '\Drupal\simple_sitemap\Controller\SimplesitemapController::get_sitemap'
_controller: '\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
requirements:
_access: 'TRUE'
simple_sitemap.chunk:
path: '/sitemaps/{sitemap_id}/sitemap.xml'
defaults:
_controller: '\Drupal\simple_sitemap\Controller\SimplesitemapController::get_sitemap'
_controller: '\Drupal\simple_sitemap\Controller\SimplesitemapController::getSitemap'
requirements:
_access: 'TRUE'
......
......@@ -16,7 +16,7 @@ use Drupal\Component\Utility\Html;
class 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 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 {
'error_message' => t('An error occurred'),
'progress_message' => t('Processing @current out of @total link types.'),
'operations' => array(),
'finished' => __CLASS__ . '::finish_batch',
'finished' => __CLASS__ . '::finishBatch',
);
$config = \Drupal::config('simple_sitemap.settings')->get('settings');
$this->batch_info = array(
$this->batchInfo = array(
'from' => $from,
'batch_process_limit' => $config['batch_process_limit'],
'max_links' => $config['max_links'],
......@@ -48,7 +48,7 @@ class Batch {
*/
public function start() {
batch_set($this->batch);
switch ($this->batch_info['from']) {
switch ($this->batchInfo['from']) {
case 'form':
break;
case 'drush':
......@@ -71,20 +71,20 @@ class Batch {
* @param string $type
* @param array $operations
*/
public function add_operations($type, $operations) {
public function addOperations($type, $operations) {
switch ($type) {
case 'entity_types':
foreach ($operations as $operation) {
$this->batch['operations'][] = array(
__CLASS__ . '::generate_bundle_urls',
array($operation['query'], $operation['info'], $this->batch_info)
__CLASS__ . '::generateBundleUrls',
array($operation['query'], $operation['info'], $this->batchInfo)
);
};
break;
case 'custom_paths':
$this->batch['operations'][] = array(
__CLASS__ . '::generate_custom_urls',
array($operations, $this->batch_info)
__CLASS__ . '::generateCustomUrls',
array($operations, $this->batchInfo)
);
break;
}
......@@ -95,10 +95,10 @@ class Batch {
*
* @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 (!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.",
array('@url' => $GLOBALS['base_url'] . '/sitemap.xml')));
......@@ -117,13 +117,13 @@ class Batch {
*
* @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();
$default_language_id = Simplesitemap::get_default_lang_id();
$default_language_id = Simplesitemap::getDefaultLangId();
// Initializing batch.
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.
......@@ -154,7 +154,7 @@ class Batch {
$result = $query->execute()->fetchAll();
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).
if (isset($route_params_field) && !empty($route_parameters = unserialize($row->$route_params_field))) {
......@@ -194,7 +194,7 @@ class Batch {
// Do not include path if it already exists.
$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;
$urls = array();
......@@ -216,8 +216,8 @@ class Batch {
'priority' => !empty($info['bundle_settings']['priority']) ? $info['bundle_settings']['priority'] : NULL,
);
}
self::set_progress_info($context, $batch_info);
self::process_segment($context, $batch_info);
self::setProgressInfo($context, $batch_info);
self::processSegment($context, $batch_info);
}
/**
......@@ -229,22 +229,22 @@ class Batch {
*
* @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();
$default_language_id = Simplesitemap::get_default_lang_id();
$default_language_id = Simplesitemap::getDefaultLangId();
// Initializing batch.
if (empty($context['sandbox'])) {
self::initialize_batch(count($custom_paths), $context);
self::InitializeBatch(count($custom_paths), $context);
}
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'];
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;
}
$options = array('absolute' => TRUE, 'language' => $languages[$default_language_id]);
......@@ -254,7 +254,7 @@ class Batch {
continue;
$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;
$urls = array();
......@@ -275,11 +275,11 @@ class Batch {
'priority' => !empty($custom_path['priority']) ? $custom_path['priority'] : NULL,
);
}
self::set_progress_info($context, $batch_info);
self::process_segment($context, $batch_info);
self::setProgressInfo($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)) {
return TRUE;
}
......@@ -287,7 +287,7 @@ class Batch {
return FALSE;
}
private static function initialize_batch($max, &$context) {
private static function InitializeBatch($max, &$context) {
$context['sandbox']['progress'] = 0;
$context['sandbox']['current_id'] = 0;
$context['sandbox']['max'] = $max;
......@@ -295,13 +295,13 @@ class Batch {
$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']['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']) {
// Providing progress info to the batch API.
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
......@@ -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']) {
$chunks = array_chunk($context['results']['generate'], $batch_info['max_links']);
foreach ($chunks as $i => $chunk_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));
}
}
......@@ -341,7 +341,7 @@ class Batch {
* @param string $type (optional)
* 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);
\Drupal::logger('simple_sitemap')->notice($message);
drupal_set_message($message, $type);
......
......@@ -24,9 +24,9 @@ class SimplesitemapController {
* @return object Response
* Returns an XML response.
*/
public function get_sitemap($sitemap_id = NULL) {
public function getSitemap($sitemap_id = NULL) {
$sitemap = \Drupal::service('simple_sitemap.generator');
$output = $sitemap->get_sitemap($sitemap_id);
$output = $sitemap->getSitemap($sitemap_id);
$output = !$output ? '' : $output;
// Display sitemap with correct xml header.
......
......@@ -21,7 +21,7 @@ class CustomLinkGenerator {
* @return array $urls
*
*/
public function get_custom_paths($custom_paths) {
public function getCustomPaths($custom_paths) {
$paths = array();
foreach($custom_paths as $i => $custom_path) {
$paths[$i]['path'] = $custom_path['path'];
......
......@@ -36,7 +36,7 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
$sitemap = \Drupal::service('simple_sitemap.generator');
$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.
if (isset($custom_link['index']) && $custom_link['index'] == 0)
......@@ -65,7 +65,7 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
'#description' => t('This setting will regenerate the whole sitemap including the above changes.'),
'#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.');
}
......@@ -77,7 +77,7 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
*/
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) {
......@@ -100,22 +100,22 @@ class SimplesitemapCustomLinksForm extends ConfigFormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$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) {
if (isset($link_config['priority'])) {
$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);
// Regenerate sitemaps according to user setting.
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_link_config = array();
foreach($custom_links_string_lines as $i => $line) {
......
......@@ -47,7 +47,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
$form['simple_sitemap_settings']['regenerate']['regenerate_submit'] = array(
'#type' => 'submit',
'#value' => t('Regenerate sitemap'),
'#submit' => array('::generate_sitemap'),
'#submit' => array('::generateSitemap'),
'#validate' => array(), // Skip form-level validator.
);
......@@ -61,7 +61,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
'#type' => 'checkbox',
'#title' => t('Regenerate the sitemap on every cron run'),
'#description' => t('Uncheck this if you intend to only regenerate the sitemap manually or via drush.'),
'#default_value' => $sitemap->get_setting('cron_generate'),
'#default_value' => $sitemap->getSetting('cron_generate'),
);
$form['simple_sitemap_settings']['advanced'] = array(
......@@ -74,7 +74,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
'#type' => 'checkbox',
'#title' => t('Remove duplicate links'),
'#description' => t('Uncheck this to significantly speed up the sitemap generation process on a huge site (>20 000 entities).'),
'#default_value' => $sitemap->get_setting('remove_duplicates'),
'#default_value' => $sitemap->getSetting('remove_duplicates'),
);
$form['simple_sitemap_settings']['advanced']['max_links'] = array(
......@@ -83,7 +83,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
'#type' => 'textfield',
'#maxlength' => 5,
'#size' => 5,
'#default_value' => $sitemap->get_setting('max_links'),
'#default_value' => $sitemap->getSetting('max_links'),
);
$form['simple_sitemap_settings']['advanced']['batch_process_limit'] = array(
......@@ -92,7 +92,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
'#type' => 'textfield',
'#maxlength' => 5,
'#size' => 5,
'#default_value' => $sitemap->get_setting('batch_process_limit'),
'#default_value' => $sitemap->getSetting('batch_process_limit'),
);
return parent::buildForm($form, $form_state);
......@@ -120,15 +120,15 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$sitemap = \Drupal::service('simple_sitemap.generator');
$sitemap->save_setting('max_links', $form_state->getValue('max_links'));
$sitemap->save_setting('cron_generate', $form_state->getValue('cron_generate'));
$sitemap->save_setting('remove_duplicates', $form_state->getValue('remove_duplicates'));
$sitemap->save_setting('batch_process_limit', $form_state->getValue('batch_process_limit'));
$sitemap->saveSetting('max_links', $form_state->getValue('max_links'));
$sitemap->saveSetting('cron_generate', $form_state->getValue('cron_generate'));
$sitemap->saveSetting('remove_duplicates', $form_state->getValue('remove_duplicates'));
$sitemap->saveSetting('batch_process_limit', $form_state->getValue('batch_process_limit'));
parent::submitForm($form, $form_state);
}
public function generate_sitemap(array &$form, FormStateInterface $form_state) {
public function generateSitemap(array &$form, FormStateInterface $form_state) {
$sitemap = \Drupal::service('simple_sitemap.generator');
$sitemap->generate_sitemap();
$sitemap->generateSitemap();
}
}
......@@ -40,7 +40,7 @@ class Simplesitemap {
* @return array containing the entity_type_id and the bundle_name of the
* form object or FALSE if none found or not supported by an existing plugin.
*/
public static function get_sitemap_form_entity_data($form_state, $form_id) {
public static function getSitemapFormEntityData($form_state, $form_id) {
// Get all simple_sitemap plugins.
$manager = \Drupal::service('plugin.manager.simple_sitemap');
......@@ -61,7 +61,7 @@ class Simplesitemap {
// Else get entity type id and bundle name from the form if available and only
// if a simple_sitemap plugin of the same entity type exists.
$form_entity = self::get_form_entity($form_state);
$form_entity = self::getFormEntity($form_state);
if ($form_entity !== FALSE) {
$form_entity_type_id = $form_entity->getEntityTypeId();
if (isset($plugins[$form_entity_type_id])) {
......@@ -88,7 +88,7 @@ class Simplesitemap {
* @return object $entity or FALSE if non-existent or if form operation is
* 'delete'.
*/
private static function get_form_entity($form_state) {
private static function getFormEntity($form_state) {
$form_object = $form_state->getFormObject();
if (!is_null($form_object)
&& method_exists($form_state->getFormObject(), 'getEntity')
......@@ -99,20 +99,6 @@ class Simplesitemap {
return FALSE;
}
/**
* Gets sitemap from db.
*/
private function get_sitemap_from_db() {
$this->sitemap = db_query("SELECT * FROM {simple_sitemap}")->fetchAllAssoc('id');
}
/**
* Gets sitemap settings from the configuration storage.
*/
private function get_config_from_db() {
$this->config = \Drupal::config('simple_sitemap.settings');
}
/**
* Gets a specific sitemap configuration from the configuration storage.
*
......@@ -121,7 +107,7 @@ class Simplesitemap {
* @return mixed
* The requested configuration.
*/
public function get_config($key) {
public function getConfig($key) {
return $this->config->get($key);
}
......@@ -133,7 +119,7 @@ class Simplesitemap {
* @param mixed $value
* The configuration to be saved.
*/
public function save_config($key, $value) {
public function saveConfig($key, $value) {
\Drupal::service('config.factory')->getEditable('simple_sitemap.settings')
->set($key, $value)->save();
}
......@@ -149,12 +135,12 @@ class Simplesitemap {
* whole sitemap, if the amount of links does not exceed the max links setting.
* If a sitemap id is provided, a sitemap chunk is returned.
*/
public function get_sitemap($sitemap_id = NULL) {
public function getSitemap($sitemap_id = NULL) {
if (is_null($sitemap_id) || !isset($this->sitemap[$sitemap_id])) {
// Return sitemap index, if there are multiple sitemap chunks.
if (count($this->sitemap) > 1) {
return $this->get_sitemap_index();
return $this->getSitemapIndex();
}
// Return sitemap if there is only one chunk.
......@@ -174,13 +160,13 @@ class Simplesitemap {
/**
* Generates the sitemap for all languages and saves it to the db.
*/
public function generate_sitemap($from = 'form') {
public function generateSitemap($from = 'form') {
Cache::invalidateTags(array('simple_sitemap'));
db_truncate('simple_sitemap')->execute();
$generator = new SitemapGenerator($from);
$generator->set_custom_links($this->get_config('custom'));
$generator->set_entity_types($this->get_config('entity_types'));
$generator->start_batch();
$generator->setCustomLinks($this->getConfig('custom'));
$generator->setEntityTypes($this->getConfig('entity_types'));
$generator->startBatch();
}
/**
......@@ -189,9 +175,9 @@ class Simplesitemap {
* @return string
* The sitemap index.
*/
private function get_sitemap_index() {
private function getSitemapIndex() {
$generator = new SitemapGenerator();
return $generator->generate_sitemap_index($this->sitemap);
return $generator->generateSitemapIndex($this->sitemap);
}
/**
......@@ -203,8 +189,8 @@ class Simplesitemap {
* @return mixed
* The current setting from db or FALSE if setting does not exist.
*/
public function get_setting($name) {
$settings = $this->get_config('settings');
public function getSetting($name) {
$settings = $this->getConfig('settings');
return isset($settings[$name]) ? $settings[$name] : FALSE;
}
......@@ -216,10 +202,10 @@ class Simplesitemap {
* @param $setting
* The setting to be saved.
*/
public function save_setting($name, $setting) {
$settings = $this->get_config('settings');
public function saveSetting($name, $setting) {
$settings = $this->getConfig('settings');
$settings[$name] = $setting;
$this->save_config('settings', $settings);
$this->saveConfig('settings', $settings);
}
/**
......@@ -228,7 +214,7 @@ class Simplesitemap {
* @return mixed
* Formatted timestamp of last sitemap generation, otherwise FALSE.
*/
public function get_generated_ago() {
public function getGeneratedAgo() {
if (isset($this->sitemap[1]->sitemap_created)) {
return \Drupal::service('date.formatter')
->formatInterval(REQUEST_TIME - $this->sitemap[1]->sitemap_created);
......@@ -236,7 +222,7 @@ class Simplesitemap {
return FALSE;
}
public static function get_default_lang_id() {
public static function getDefaultLangId() {
return \Drupal::languageManager()->getDefaultLanguage()->getId();
}
}
......@@ -23,14 +23,14 @@ class SitemapGenerator {
const XMLNS = 'http://www.sitemaps.org/schemas/sitemap/0.9';
const XMLNS_XHTML = 'http://www.w3.org/1999/xhtml';
private $entity_types;
private $entityTypes;
private $custom;
private $links;
private $generating_from;
private $generatingFrom;
function __construct($from = 'form') {
$this->links = array();
$this->generating_from = $from;
$this->generatingFrom = $from;
}
/**
......@@ -38,7 +38,7 @@ class SitemapGenerator {
*
* @return array $options
*/
public static function get_priority_select_values() {
public static function getPrioritySelectValues() {
$options = array();
foreach(range(0, self::PRIORITY_HIGHEST) as $value) {
$value = $value / self::PRIORITY_DIVIDER;
......@@ -47,21 +47,21 @@ class SitemapGenerator {
return $options;
}
public function set_entity_types($entity_types) {
$this->entity_types = is_array($entity_types) ? $entity_types : array();
public function setEntityTypes($entityTypes) {
$this->entityTypes = is_array($entityTypes) ? $entityTypes : array();
}
public function set_custom_links($custom) {
public function setCustomLinks($custom) {
$this->custom = is_array($custom) ? $custom : array();
}
/**
* Adds all operations to the batch and starts it.
*/
public function start_batch() {
$batch = new Batch($this->generating_from);
$batch->add_operations('custom_paths', $this->batch_add_custom_paths());
$batch->add_operations('entity_types', $this->batch_add_entity_type_paths());
public function startBatch() {
$batch = new Batch($this->generatingFrom);
$batch->addOperations('custom_paths', $this->batchAddCustomPaths());
$batch->addOperations('entity_types', $this->batchAddEntityTypePaths());
$batch->start();
}
......@@ -70,9 +70,9 @@ class SitemapGenerator {
*
* @return array $operation.
*/
private function batch_add_custom_paths() {
private function batchAddCustomPaths() {
$link_generator = new CustomLinkGenerator();
return $link_generator->get_custom_paths($this->custom);
return $link_generator->getCustomPaths($this->custom);
}
/**
......@@ -81,7 +81,7 @@ class SitemapGenerator {
*
* @return array $operations.
*/
private function batch_add_entity_type_paths() {
private function batchAddEntityTypePaths() {
$manager = \Drupal::service('plugin.manager.simple_sitemap');
$plugins = $manager->getDefinitions();
......@@ -89,9 +89,9 @@ class SitemapGenerator {
// Let all simple_sitemap plugins add their links to the sitemap.
foreach ($plugins as $link_generator_plugin) {
if (isset($this->entity_types[$link_generator_plugin['id']])) {
if (isset($this->entityTypes[$link_generator_plugin['id']])) {
$instance = $manager->createInstance($link_generator_plugin['id']);
foreach($this->entity_types[$link_generator_plugin['id']] as $bundle => $bundle_settings) {
foreach($this->entityTypes[$link_generator_plugin['id']] as $bundle => $bundle_settings) {
if ($bundle_settings['index']) {
$operation['info'] = $instance->getInfo();
$operation['query'] = $instance->getQuery($bundle);
......@@ -111,10 +111,10 @@ class SitemapGenerator {
* @param array $links
* All links with their multilingual versions and settings.
*/
public static function generate_sitemap($links) {
public static function generateSitemap($links) {
$values = array(
'id' => db_query('SELECT MAX(id) FROM {simple_sitemap}')->fetchField() + 1,
'sitemap_string' => self::generate_sitemap_chunk($links),
'sitemap_string' => self::generateSitemapChunk($links),
'sitemap_created' => REQUEST_TIME,
);
db_insert('simple_sitemap')->fields($values)->execute();
......@@ -128,7 +128,7 @@ class SitemapGenerator {
*