Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"drupal/seckit": "2.0.3",
"drupal/slick": "3.0.7",
"drupal/slick_views": "3.0.3",
"drupal/simple_sitemap": "4.2.3",
"drupal/smart_date": "4.3.0",
"drupal/smart_title": "1.0.0",
"drupal/smtp": "1.4.0",
Expand Down
3 changes: 2 additions & 1 deletion config/install/user.role.az_content_admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ permissions:
- 'administer taxonomy'
- 'administer url aliases'
- 'administer webform overview'
- 'administer xmlsitemap'
- 'batch update workbench access'
- 'bypass node access'
- 'bypass workbench access'
Expand Down Expand Up @@ -108,3 +107,5 @@ permissions:
- 'view disabled publication type entities'
- 'view enabled publication type entities'
- 'view post access counter'
- 'administer sitemap settings'
- 'edit entity sitemap settings'
4 changes: 1 addition & 3 deletions config/optional/config_ignore.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ ignored_config_entities:
- 'language.entity.*'
- 'metatag.metatag_defaults.*'
- 'shortcut.set.*'
- simple_sitemap.settings
- 'system.menu.*'
- system.site
- 'taxonomy.vocabulary.*'
- 'webform.webform.*'
- xmlsitemap.settings
- 'xmlsitemap.settings.*.*'
- 'xmlsitemap.xmlsitemap.*'
54 changes: 40 additions & 14 deletions modules/custom/az_publication/az_publication.module
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Datetime\Element\Datetime;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
Expand All @@ -17,6 +18,7 @@ use Drupal\az_publication\Plugin\views\argument\AZCitationStyleArgument;
use Drupal\filter\Entity\FilterFormat;
use Drupal\node\Entity\NodeType;
use Drupal\node\NodeInterface;
use Drupal\simple_sitemap\Exception\SkipElementException;
use Drupal\views\Plugin\Block\ViewsBlock;
use Seboettg\CiteProc\CiteProc;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -864,32 +866,56 @@ function template_preprocess_az_inline_entity_role_form_entity_table(array &$var
}
}

/**
* Determines whether a publication node is noncanonical for sitemap indexing.
*/
function az_publication_is_noncanonical_for_sitemap(NodeInterface $entity): bool {
if ($entity->bundle() !== 'az_publication') {
return FALSE;
}

$canonicals = [
'field_az_publication_doi',
'field_az_publication_link',
];

foreach ($canonicals as $canonical) {
if ($entity->hasField($canonical) && !empty($entity->get($canonical)->getValue())) {
return TRUE;
}
}

return FALSE;
}

/**
* Implements hook_xmlsitemap_link_alter().
*
* Legacy compatibility hook for XML Sitemap.
*
* Prefer az_publication_simple_sitemap_entity_process() for exclusion logic.
*/
function az_publication_xmlsitemap_link_alter(array &$link, array $context) {

// Modify publication links to not appear if they are noncanonical.
// This behavior is skipped for overridden links.
if (!empty($context['entity']) && $context['entity'] instanceof NodeInterface && $link['access'] && ($context['entity']->bundle() === 'az_publication') && (empty($link['status_override']))) {
// Fields that represent a canonical copy of the publication exists.
$canonicals = [
'field_az_publication_doi',
'field_az_publication_link',
];

// If a publication has a canonical field, exclude this publication..
if (!empty($context['entity']) && $context['entity'] instanceof NodeInterface && $link['access'] && empty($link['status_override'])) {
$entity = $context['entity'];
foreach ($canonicals as $canonical) {
// Publications are noncanonical if a canonical reference exists.
if ($entity->hasField($canonical) && !empty($entity->get($canonical)->getValue())) {
$link['access'] = FALSE;
break;
}
if (az_publication_is_noncanonical_for_sitemap($entity)) {
$link['access'] = FALSE;
}
}
}

/**
* Implements hook_simple_sitemap_entity_process().
*/
function az_publication_simple_sitemap_entity_process(ContentEntityInterface $entity): void {
if ($entity instanceof NodeInterface && az_publication_is_noncanonical_for_sitemap($entity)) {
throw new SkipElementException();
}
}

/**
* Implements hook_views_data_alter().
*
Expand Down
1 change: 0 additions & 1 deletion modules/custom/az_search_api/az_search_api.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ dependencies:
- search_api_attachments:search_api_attachments
- search_api_solr:search_api_solr
- searchstax:searchstax
- xmlsitemap:xmlsitemap
16 changes: 16 additions & 0 deletions modules/custom/az_search_api/az_search_api.install
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,19 @@
function az_search_api_update_1021401() {
\Drupal::service('module_installer')->install(['search_api_attachments']);
}

/**
* Migrate XML sitemap base URL state to simple_sitemap settings.
*/
function az_search_api_update_1021402() {
$config = \Drupal::configFactory()->getEditable('simple_sitemap.settings');
if ($config->get('base_url')) {
return;
}

$legacy_base_url = \Drupal::state()->get('xmlsitemap_base_url');
if (!empty($legacy_base_url)) {
$config->set('base_url', rtrim($legacy_base_url, '/'));
$config->save();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Transforms base_url into a value matching xmlsitemap.
* Transforms base_url into a value matching sitemap generation settings.
*/
#[SearchApiProcessor(
id: 'az_base_url',
label: new TranslatableMarkup('Transform Base URL'),
description: new TranslatableMarkup('Transform the base url with the XML sitemap default'),
description: new TranslatableMarkup('Transform the base url with the sitemap base URL override'),
stages: [
'pre_index_save' => 0,
'preprocess_index' => -10,
Expand All @@ -37,9 +37,14 @@ public static function create(ContainerInterface $container, array $configuratio
/** @var static $processor */
$processor = parent::create($container, $configuration, $plugin_id, $plugin_definition);

// \Drupal\Core\State\StateInterface $state;
$state = $container->get('state');
$baseUrl = $state->get('xmlsitemap_base_url');
$config = $container->get('config.factory')->get('simple_sitemap.settings');
$baseUrl = $config->get('base_url');

// Backward compatible fallback for sites that have not migrated settings.
if (empty($baseUrl)) {
$baseUrl = $container->get('state')->get('xmlsitemap_base_url');
}

if (!empty($baseUrl)) {
// Append a trailing slash if there isn't one.
if (!str_ends_with($baseUrl, '/')) {
Expand Down
4 changes: 2 additions & 2 deletions modules/custom/az_seo/az_seo.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package: The University of Arizona
container_rebuild_required: true
dependencies:
- az_core:az_core
- xmlsitemap:xmlsitemap
- xmlsitemap:xmlsitemap_engines
- simple_sitemap:simple_sitemap
- simple_sitemap:simple_sitemap_engines
- redirect:redirect
- metatag:metatag
- metatag:metatag_open_graph
Expand Down
Loading
Loading