Commit 2cd4f16c authored by gbyte.co's avatar gbyte.co

Code sniffer automatic fixes

parent 63fc8453
<?php
/**
* @file
* Hooks provided by the Simple XML sitemap module.
*/
/**
* @addtogroup hooks
* @{
......@@ -15,12 +15,12 @@
* This hook gets invoked for every sitemap chunk generated.
*
* @param array &$links
* Array containing multilingual links generated for each path to be indexed.
* Array containing multilingual links generated for each path to be indexed.
*/
function hook_simple_sitemap_links_alter(&$links) {
// Remove German URL for a certain path in the hreflang sitemap.
foreach($links as &$link) {
foreach ($links as &$link) {
if ($link['path'] == 'node/1') {
// Remove 'loc' URL if it points to a german site.
if ($link['langcode'] == 'de') {
......@@ -38,4 +38,3 @@ function hook_simple_sitemap_links_alter(&$links) {
/**
* @} End of "addtogroup hooks".
*/
<?php
/**
* @file
* Drush integration.
......
<?php
/**
* @file
* Module install and update procedures.
......@@ -19,7 +20,7 @@ function simple_sitemap_requirements($phase) {
];
}
switch($phase) {
switch ($phase) {
case 'runtime':
$generated_ago = \Drupal::service('simple_sitemap.generator')->getGeneratedAgo();
if (!$generated_ago) {
......@@ -96,7 +97,7 @@ function simple_sitemap_update_8201() {
'commerce_product_type' => 'commerce_product',
'media_bundle' => 'media',
];
foreach($entity_types as $entity_type_name => $settings) {
foreach ($entity_types as $entity_type_name => $settings) {
if (isset($naming_changes[$entity_type_name])) {
$entity_types[$naming_changes[$entity_type_name]] = $entity_types[$entity_type_name];
unset($entity_types[$entity_type_name]);
......
<?php
/**
* @file
* Main module file containing hooks.
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help.
*/
function simple_sitemap_help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_match) {
function simple_sitemap_help($route_name, RouteMatchInterface $route_match) {
return $route_name === 'help.page.simple_sitemap' ?
check_markup(file_get_contents(dirname(__FILE__) . "/README.txt")) : NULL;
}
......@@ -19,8 +22,9 @@ function simple_sitemap_help($route_name, \Drupal\Core\Routing\RouteMatchInterfa
*/
function simple_sitemap_form_alter(&$form, $form_state, $form_id) {
$f = \Drupal::service('simple_sitemap.form_helper')->processForm($form_state);
if (!$f->alteringForm)
if (!$f->alteringForm) {
return;
}
$form['simple_sitemap'] = [
'#type' => 'details',
......@@ -29,14 +33,17 @@ function simple_sitemap_form_alter(&$form, $form_state, $form_id) {
'#description' => $f->entityCategory == 'instance' ? t('Settings for this entity can be overridden here.') : '',
];
// Attach some js magic to forms.
if ($f->entityTypeId != 'comment' || $f->entityCategory != 'instance') // todo: JS not working on comment entity form, hence disabling.
// todo: JS not working on comment entity form, hence disabling.
if ($f->entityTypeId != 'comment' || $f->entityCategory != 'instance') {
$form['#attached']['library'][] = 'simple_sitemap/form';
}
// Only attach fieldset summary js to 'additional settings' vertical tabs.
if (isset($form['additional_settings'])) {
$form['#attached']['library'][] = 'simple_sitemap/fieldsetSummaries';
}
$f->displayEntitySettings($form['simple_sitemap'])
->displayRegenerateNow($form['simple_sitemap']); // todo: do not show setting when creating new bundle
// todo: do not show setting when creating new bundle.
->displayRegenerateNow($form['simple_sitemap']);
// Add submission handler.
if (isset($form['actions']['submit']['#submit'])) {
......@@ -46,7 +53,8 @@ function simple_sitemap_form_alter(&$form, $form_state, $form_id) {
}
}
}
else { // Fix for account page rendering other submit handlers not usable.
// Fix for account page rendering other submit handlers not usable.
else {
$form['#submit'][] = 'simple_sitemap_entity_form_submit';
}
}
......@@ -114,7 +122,7 @@ function simple_sitemap_entity_bundle_delete($entity_type_id, $bundle) {
if ($generator->getSetting('cron_generate')) {
$message .= '</br>' . t('Otherwise the sitemap will be regenerated on the next cron run.');
}
// drupal_set_message($message); // todo: Commented out, as html code is visible.
// drupal_set_message($message); // todo: Commented out, as html code is visible.
}
}
......@@ -123,15 +131,15 @@ function simple_sitemap_entity_bundle_delete($entity_type_id, $bundle) {
*
* Removes settings of the removed entity.
*/
function simple_sitemap_entity_delete(Drupal\Core\Entity\EntityInterface $entity) {
function simple_sitemap_entity_delete(EntityInterface $entity) {
$generator = \Drupal::service('simple_sitemap.generator');
$entity_types = $generator->getConfig('entity_types');
$entity_type_id = $entity->getEntityTypeId();
$bundle_name = !empty($entity->bundle()) ? $entity->bundle() : $entity_type_id;
$bundle_name = $bundle_name == 'menu_link_content'&& method_exists($entity, 'getMenuName') ? $entity->getMenuName() : $bundle_name; // Menu fix.
// Menu fix.
$bundle_name = $bundle_name == 'menu_link_content'&& method_exists($entity, 'getMenuName') ? $entity->getMenuName() : $bundle_name;
if (isset($entity_types[$entity_type_id][$bundle_name]['entities'][$entity->id()])) {
unset($entity_types[$entity_type_id][$bundle_name]['entities'][$entity->id()]);
$generator->saveConfig('entity_types', $entity_types);
}
}
......@@ -4,6 +4,9 @@ namespace Drupal\simple_sitemap\Batch;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
*
*/
class Batch {
use StringTranslationTrait;
......@@ -25,7 +28,8 @@ class Batch {
'error_message' => $this->t(self::BATCH_ERROR_MESSAGE),
'progress_message' => $this->t(self::BATCH_PROGRESS_MESSAGE),
'operations' => [],
'finished' => [__CLASS__, 'finishGeneration'], // __CLASS__ . '::finishGeneration' not working possibly due to a drush error.
// __CLASS__ . '::finishGeneration' not working possibly due to a drush error.
'finished' => [__CLASS__, 'finishGeneration'],
];
}
......@@ -61,7 +65,8 @@ class Batch {
batch_set($this->batch);
$this->batch =& batch_get();
$this->batch['progressive'] = FALSE;
batch_process(); //todo: Does not take advantage of batch API and eventually runs out of memory on very large sites.
// todo: Does not take advantage of batch API and eventually runs out of memory on very large sites.
batch_process();
break;
case 'nobatch':
......@@ -69,7 +74,7 @@ class Batch {
// within one process (so in fact not using batch API here, just
// mimicking it to avoid code duplication.
$context = [];
foreach($this->batch['operations'] as $i => $operation) {
foreach ($this->batch['operations'] as $i => $operation) {
$operation[1][] = &$context;
call_user_func_array($operation[0], $operation[1]);
}
......@@ -86,7 +91,7 @@ class Batch {
*/
public function addOperation($processing_method, $data) {
$this->batch['operations'][] = [
__CLASS__ . '::' . $processing_method, [$data, $this->batchInfo]
__CLASS__ . '::' . $processing_method, [$data, $this->batchInfo],
];
}
......@@ -133,4 +138,5 @@ class Batch {
BatchUrlGenerator::service()
->finishGeneration($success, $results, $operations);
}
}
......@@ -8,7 +8,8 @@ use Drupal\Core\Cache\Cache;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* Class BatchUrlGenerator
* Class BatchUrlGenerator.
*
* @package Drupal\simple_sitemap\Batch
*/
class BatchUrlGenerator {
......@@ -18,7 +19,7 @@ class BatchUrlGenerator {
const ANONYMOUS_USER_ID = 0;
const PATH_DOES_NOT_EXIST_OR_NO_ACCESS_MESSAGE = "The path @path has been omitted from the XML sitemap as it either does not exist, or it is not accessible to anonymous users.";
const PROCESSING_PATH_MESSAGE = 'Processing path #@current out of @max: @path';
const REGENERATION_FINISHED_MESSAGE= "The <a href='@url' target='_blank'>XML sitemap</a> has been regenerated for all languages.";
const REGENERATION_FINISHED_MESSAGE = "The <a href='@url' target='_blank'>XML sitemap</a> has been regenerated for all languages.";
protected $sitemapGenerator;
protected $languageManager;
......@@ -35,6 +36,7 @@ class BatchUrlGenerator {
/**
* BatchUrlGenerator constructor.
*
* @param $sitemap_generator
* @param $language_manager
* @param $entity_type_manager
......@@ -50,7 +52,8 @@ class BatchUrlGenerator {
$entity_query,
$logger
) {
$this->sitemapGenerator = $sitemap_generator; //todo using only one method, maybe make method static instead?
// Todo using only one method, maybe make method static instead?
$this->sitemapGenerator = $sitemap_generator;
$this->languageManager = $language_manager;
$this->languages = $language_manager->getLanguages();
$this->defaultLanguageId = $language_manager->getDefaultLanguage()->getId();
......@@ -148,6 +151,9 @@ class BatchUrlGenerator {
}
}
/**
*
*/
protected function processSegment() {
if ($this->isBatch()) {
$this->setProgressInfo();
......@@ -166,6 +172,9 @@ class BatchUrlGenerator {
}
}
/**
*
*/
protected function setProgressInfo() {
if ($this->context['sandbox']['progress'] != $this->context['sandbox']['max']) {
// Providing progress info to the batch API.
......@@ -191,12 +200,15 @@ class BatchUrlGenerator {
public function generateBundleUrls($entity_info) {
$query = $this->entityQuery->get($entity_info['entity_type_name']);
if (!empty($entity_info['keys']['id']))
if (!empty($entity_info['keys']['id'])) {
$query->sort($entity_info['keys']['id'], 'ASC');
if (!empty($entity_info['keys']['bundle']))
}
if (!empty($entity_info['keys']['bundle'])) {
$query->condition($entity_info['keys']['bundle'], $entity_info['bundle_name']);
if (!empty($entity_info['keys']['status']))
}
if (!empty($entity_info['keys']['status'])) {
$query->condition($entity_info['keys']['status'], 1);
}
$count_query = clone $query;
$this->initializeBatch($count_query->count()->execute());
......@@ -210,7 +222,7 @@ class BatchUrlGenerator {
if (!empty($results)) {
$entities = $this->entityTypeManager->getStorage($entity_info['entity_type_name'])->loadMultiple($results);
foreach($entities as $entity_id => $entity) {
foreach ($entities as $entity_id => $entity) {
$this->setCurrentId($entity_id);
$priority = NULL;
......@@ -226,27 +238,35 @@ class BatchUrlGenerator {
}
switch ($entity_info['entity_type_name']) {
case 'menu_link_content': // Loading url object for menu links.
if (!$entity->isEnabled())
// Loading url object for menu links.
case 'menu_link_content':
if (!$entity->isEnabled()) {
continue;
}
$url_object = $entity->getUrlObject();
break;
default: // Loading url object for other entities.
$url_object = $entity->toUrl(); //todo: file entity type does not have a canonical url and breaks generation, hopefully fixed in https://www.drupal.org/node/2402533
// Loading url object for other entities.
default:
// todo: file entity type does not have a canonical url and breaks generation, hopefully fixed in https://www.drupal.org/node/2402533
$url_object = $entity->toUrl();
}
// Do not include external paths.
if (!$url_object->isRouted())
if (!$url_object->isRouted()) {
continue;
}
// Do not include paths inaccessible to anonymous users.
if (!$url_object->access($this->anonUser))
if (!$url_object->access($this->anonUser)) {
continue;
}
// Do not include paths that have been already indexed.
$path = $url_object->getInternalPath();
if ($this->batchInfo['remove_duplicates'] && $this->pathProcessed($path))
if ($this->batchInfo['remove_duplicates'] && $this->pathProcessed($path)) {
continue;
}
$url_object->setOption('absolute', TRUE);
......@@ -271,21 +291,24 @@ class BatchUrlGenerator {
$this->initializeBatch(count($custom_paths));
foreach($custom_paths as $i => $custom_path) {
foreach ($custom_paths as $i => $custom_path) {
$this->setCurrentId($i);
if (!$this->pathValidator->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. Use getUrlIfValidWithoutAccessCheck()?
// 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. Use getUrlIfValidWithoutAccessCheck()?
if (!$this->pathValidator->isValid($custom_path['path'])) {
$this->logger->registerError([self::PATH_DOES_NOT_EXIST_OR_NO_ACCESS_MESSAGE, ['@path' => $custom_path['path']]], 'warning');
continue;
}
$url_object = Url::fromUserInput($custom_path['path'], ['absolute' => TRUE]);
if (!$url_object->access($this->anonUser))
if (!$url_object->access($this->anonUser)) {
continue;
}
$path = $url_object->getInternalPath();
if ($this->batchInfo['remove_duplicates'] && $this->pathProcessed($path))
if ($this->batchInfo['remove_duplicates'] && $this->pathProcessed($path)) {
continue;
}
// Load entity object if this is an entity route.
$route_parameters = $url_object->getRouteParameters();
......@@ -324,7 +347,7 @@ class BatchUrlGenerator {
->toString();
}
else {
foreach($translation_languages as $language) {
foreach ($translation_languages as $language) {
if (!is_null($entity) && $this->batchInfo['skip_untranslated']) {
$translation = $entity->getTranslation($language->getId());
if (!$translation->access('view')) {
......@@ -337,7 +360,7 @@ class BatchUrlGenerator {
}
}
foreach($alternate_urls as $langcode => $url) {
foreach ($alternate_urls as $langcode => $url) {
$this->context['results']['generate'][] = $path_data + ['langcode' => $langcode, 'url' => $url, 'alternate_urls' => $alternate_urls];
}
}
......@@ -358,7 +381,8 @@ class BatchUrlGenerator {
['@url' => $GLOBALS['base_url'] . '/sitemap.xml']));
}
else {
//todo: register error
// todo: register error.
}
}
}
......@@ -9,7 +9,8 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class SimplesitemapController
* Class SimplesitemapController.
*
* @package Drupal\simple_sitemap\Controller
*/
class SimplesitemapController extends ControllerBase {
......@@ -35,13 +36,13 @@ class SimplesitemapController extends ControllerBase {
* Returns the whole sitemap, a requested sitemap chunk, or the sitemap index file.
*
* @param int $chunk_id
* Optional ID of the sitemap chunk. If none provided, the first chunk or
* the sitemap index is fetched.
* Optional ID of the sitemap chunk. If none provided, the first chunk or
* the sitemap index is fetched.
*
* @throws NotFoundHttpException
*
* @return object
* Returns an XML response.
* Returns an XML response.
*/
public function getSitemap($chunk_id = NULL) {
$output = $this->generator->getSitemap($chunk_id);
......@@ -62,4 +63,5 @@ class SimplesitemapController extends ControllerBase {
public static function create(ContainerInterface $container) {
return new static($container->get('simple_sitemap.generator'));
}
}
......@@ -5,7 +5,8 @@ namespace Drupal\simple_sitemap\Form;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* Class FormHelper
* Class FormHelper.
*
* @package Drupal\simple_sitemap\Form
*/
class FormHelper {
......@@ -29,13 +30,13 @@ class FormHelper {
'default',
'edit',
'add',
'register'
'register',
];
private static $valuesToCheck = [
'simple_sitemap_index_content',
'simple_sitemap_priority',
'simple_sitemap_regenerate_now'
'simple_sitemap_regenerate_now',
];
/**
......@@ -98,25 +99,32 @@ class FormHelper {
return $this;
}
/**
*
*/
private function assertAlteringForm() {
// Do not alter the form if user lacks certain permissions.
if (!$this->currentUser->hasPermission('administer sitemap settings'))
if (!$this->currentUser->hasPermission('administer sitemap settings')) {
$this->alteringForm = FALSE;
}
// Do not alter the form if it is irrelevant to sitemap generation.
elseif (empty($this->entityCategory))
elseif (empty($this->entityCategory)) {
$this->alteringForm = FALSE;
}
// Do not alter the form if entity is not enabled in sitemap settings.
elseif (!$this->generator->entityTypeIsEnabled($this->entityTypeId))
elseif (!$this->generator->entityTypeIsEnabled($this->entityTypeId)) {
$this->alteringForm = FALSE;
}
// Do not alter the form, if sitemap is disabled for the entity type of this
// entity instance.
elseif ($this->entityCategory == 'instance'
&& !$this->generator->bundleIsIndexed($this->entityTypeId, $this->bundleName))
&& !$this->generator->bundleIsIndexed($this->entityTypeId, $this->bundleName)) {
$this->alteringForm = FALSE;
}
}
/**
......@@ -160,17 +168,19 @@ class FormHelper {
'#options' => [
0 => $this->entityCategory == 'instance' ? $this->t('Do not index this @bundle entity', ['@bundle' => $bundle_name]) : $this->t('Do not index entities of this type'),
1 => $this->entityCategory == 'instance' ? $this->t('Index this @bundle entity', ['@bundle' => $bundle_name]) : $this->t('Index entities of this type'),
]
],
];
if ($this->entityCategory == 'instance' && isset($bundle_settings['index'])) {
$form_fragment[$prefix . 'simple_sitemap_index_content']['#options'][$bundle_settings['index']] .= ' <em>(' . $this->t('Default') . ')</em>';
}
}
if ($this->entityCategory == 'instance')
if ($this->entityCategory == 'instance') {
$priority_description = $this->t('The priority this @bundle entity will have in the eyes of search engine bots.', ['@bundle' => $bundle_name]);
else
}
else {
$priority_description = $this->t('The priority entities of this type will have in the eyes of search engine bots.');
}
$form_fragment[$prefix . 'simple_sitemap_priority'] = [
'#type' => 'select',
'#title' => $this->t('Priority'),
......@@ -179,7 +189,7 @@ class FormHelper {
'#options' => $this->getPrioritySelectValues(),
];
if ($this->entityCategory == 'instance' && isset($bundle_settings['priority'])) {
$form_fragment[$prefix . 'simple_sitemap_priority']['#options'][(string)$bundle_settings['priority']] .= ' (' . $this->t('Default') . ')';
$form_fragment[$prefix . 'simple_sitemap_priority']['#options'][(string) $bundle_settings['priority']] .= ' (' . $this->t('Default') . ')';
}
return $this;
}
......@@ -189,7 +199,7 @@ class FormHelper {
* and gathers sitemap settings from the database.
*
* @return bool
* TRUE if this is a bundle or bundle instance form, FALSE otherwise.
* TRUE if this is a bundle or bundle instance form, FALSE otherwise.
*/
private function getEntityDataFromFormEntity() {
$form_entity = $this->getFormEntity();
......@@ -200,7 +210,7 @@ class FormHelper {
$this->entityCategory = 'instance';
}
else {
foreach($sitemap_entity_types as $sitemap_entity) {
foreach ($sitemap_entity_types as $sitemap_entity) {
if ($sitemap_entity->getBundleEntityType() == $entity_type_id) {
$this->entityCategory = 'bundle';
break;
......@@ -221,7 +231,8 @@ class FormHelper {
case 'instance':
$this->entityTypeId = $entity_type_id;
$this->bundleName = $this->generator->getEntityInstanceBundleName($form_entity);
$this->instanceId = !empty($form_entity->id()) ? $form_entity->id() : NULL; // New menu link's id is '' instead of NULL, hence checking for empty.
// New menu link's id is '' instead of NULL, hence checking for empty.
$this->instanceId = !empty($form_entity->id()) ? $form_entity->id() : NULL;
break;
default:
......@@ -236,8 +247,8 @@ class FormHelper {
* Gets the object entity of the form if available.
*
* @return object|false
* Entity or FALSE if non-existent or if form operation is
* 'delete'.
* Entity or FALSE if non-existent or if form operation is
* 'delete'.
*/
private function getFormEntity() {
$form_object = $this->formState->getFormObject();
......@@ -254,7 +265,7 @@ class FormHelper {
* To be used in an entity form submit.
*
* @return int
* Entity ID.
* Entity ID.
*/
public function getFormEntityId() {
return $this->formState->getFormObject()->getEntity()->id();
......@@ -266,8 +277,9 @@ class FormHelper {
*
* @param $form
* @param $values
*
* @return bool
* TRUE if simple_sitemap form values have been altered by the user.
* TRUE if simple_sitemap form values have been altered by the user.
*/
public function valuesChanged($form, $values) {
foreach (self::$valuesToCheck as $field_name) {
......@@ -285,7 +297,7 @@ class FormHelper {
*/
public function getPrioritySelectValues() {
$options = [];
foreach(range(0, self::PRIORITY_HIGHEST) as $value) {
foreach (range(0, self::PRIORITY_HIGHEST) as $value) {
$value = $this->formatPriority($value / self::PRIORITY_DIVIDER);
$options[$value] = $value;
}
......@@ -297,7 +309,7 @@ class FormHelper {
* @return string
*/
public function formatPriority($priority) {
return number_format((float)$priority, 1, '.', '');
return number_format((float) $priority, 1, '.', '');
}
/**
......@@ -307,4 +319,5 @@ class FormHelper {
public static function isValidPriority($priority) {
return !is_numeric($priority) || $priority < 0 || $priority > 1 ? FALSE : TRUE;
}
}
......@@ -5,7 +5,8 @@ namespace Drupal\simple_sitemap\Form;
use Drupal\Core\Form\FormStateInterface;
/**
* Class SimplesitemapCustomLinksForm
* Class SimplesitemapCustomLinksForm.
*
* @package Drupal\simple_sitemap\Form
*/
class SimplesitemapCustomLinksForm extends SimplesitemapFormBase {
......@@ -53,12 +54,13 @@ class SimplesitemapCustomLinksForm extends SimplesitemapFormBase {
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
foreach($this->getCustomLinks($form_state->getValue('custom_links')) as $i => $link_config) {
foreach ($this->getCustomLinks($form_state->getValue('custom_links')) as $i => $link_config) {
$placeholders = ['@line' => ++$i, '@path' => $link_config['path'], '@priority' => isset($link_config['priority']) ? $link_config['priority'] : ''];
// Checking if internal path exists.
if (!$this->pathValidator->isValid($link_config['path'])
|| strpos($link_config['path'], '//') !== FALSE) { // Path validator does not see a double slash as an error. Catching this to prevent breaking path generation.
// Path validator does not see a double slash as an error. Catching this to prevent breaking path generation.
|| strpos($link_config['path'], '//') !== FALSE) {
$form_state->setErrorByName('', $this->t("<strong>Line @line</strong>: The path <em>@path</em> does not exist.", $placeholders));
}
......@@ -101,7 +103,7 @@ class SimplesitemapCustomLinksForm extends SimplesitemapFormBase {
// Remove empty values and whitespaces from array.
$custom_links_string_lines = array_filter(array_map('trim', $custom_links_string_lines));
$custom_links = [];
foreach($custom_links_string_lines as $i => &$line) {
foreach ($custom_links_string_lines as $i => &$line) {
$link_settings = explode(' ', $line, 2);
$custom_links[$i]['path'] = $link_settings[0];
if (isset($link_settings[1]) && $link_settings[1] != '') {
......@@ -110,4 +112,5 @@ class SimplesitemapCustomLinksForm extends SimplesitemapFormBase {
}
return $custom_links;
}
}
......@@ -5,7 +5,8 @@ namespace Drupal\simple_sitemap\Form;
use Drupal\Core\Form\FormStateInterface;
/**
* Class SimplesitemapEntitiesForm
* Class SimplesitemapEntitiesForm.
*
* @package Drupal\simple_sitemap\Form
*/
class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
......@@ -43,10 +44,10 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
foreach ($entity_type_labels as $entity_type_id => $entity_type_label) {
$form['simple_sitemap_entities']['entities'][$entity_type_id] = [
'#type' => 'details',
'#title' => $entity_type_label,
'#open' => $this->generator->entityTypeIsEnabled($entity_type_id),
];
'#type' => 'details',
'#title' => $entity_type_label,
'#open' => $this->generator->entityTypeIsEnabled($entity_type_id),
];
$form['simple_sitemap_entities']['entities'][$entity_type_id][$entity_type_id . '_enabled'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable @entity_type_label <em>(@entity_type_id)</em> support', ['@entity_type_label' => strtolower($entity_type_label), '@entity_type_id' => $entity_type_id]),
......@@ -72,20 +73,21 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues();
foreach($values as $field_name => $value) {
foreach ($values as $field_name => $value) {
if (substr($field_name, -strlen('_enabled')) == '_enabled') {
$entity_type_id = substr($field_name, 0, -8);
if ($value) {
$this->generator->enableEntityType($entity_type_id);
if ($this->generator->entityTypeIsAtomic($entity_type_id)) {
$this->generator->setBundleSettings($entity_type_id, $entity_type_id, [
'index' => TRUE,
'priority' => $values[$entity_type_id . '_simple_sitemap_priority']
]);
'index' => TRUE,
'priority' => $values[$entity_type_id . '_simple_sitemap_priority'],
]);
}
}
else
else {
$this->generator->disableEntityType($entity_type_id);
}
}
}
parent::submitForm($form, $form_state);
......@@ -95,4 +97,5 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
$this->generator->generateSitemap();
}
}
}
......@@ -6,7 +6,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Form\ConfigFormBase;
/**
* Class SimplesitemapFormBase
* Class SimplesitemapFormBase.
*
* @package Drupal\simple_sitemap\Form
*/
abstract class SimplesitemapFormBase extends ConfigFormBase {
......@@ -46,7 +47,11 @@ abstract class SimplesitemapFormBase extends ConfigFormBase {
return ['simple_sitemap.settings'];
}
/**
*
*/
protected function getDonationText() {
return "<div class='description'>" . $this->t("If you would like to say thanks and support the development of this module, a <a target='_blank' href='@url'>donation</a> is always appreciated.", ['@url' => 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5AFYRSBLGSC3W']) . "</div>";
}
}
......@@ -5,7 +5,8 @@ namespace Drupal\simple_sitemap\Form;
use Drupal\Core\Form\FormStateInterface;
/**
* Class SimplesitemapSettingsForm
* Class SimplesitemapSettingsForm.
*
* @package Drupal\simple_sitemap\Form
*/
class SimplesitemapSettingsForm extends SimplesitemapFormBase {
......@@ -15,7 +16,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
'cron_generate',
'remove_duplicates',
'skip_untranslated',
'batch_process_limit'
'batch_process_limit',
];
/**
......@@ -42,7 +43,8 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
'#type' => 'submit',
'#value' => $this->t('Regenerate sitemap'),
'#submit' => ['::generateSitemap'],
'#validate' => [], // Skip form-level validator.
// Skip form-level validator.
'#validate' => [],
];
$form['simple_sitemap_settings']['settings'] = [
......@@ -108,7 +110,7 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
foreach($this->formSettings as $setting_name) {
foreach ($this->formSettings as $setting_name) {
$this->generator->saveSetting($setting_name, $form_state->getValue($setting_name));
}
parent::submitForm($form, $form_state);
......@@ -126,4 +128,5 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
public function generateSitemap(array &$form, FormStateInterface $form_state) {
$this->generator->generateSitemap();
}
}
......@@ -5,7 +5,8 @@ namespace Drupal\simple_sitemap;