Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/SLB-473-revision-link' into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/drupal/custom/custom.module
  • Loading branch information
colorfield committed Sep 6, 2024
2 parents 3c8171a + e11ba47 commit c55bb4a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/drupal/custom/custom.module
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use Drupal\media\Entity\Media;
use Drupal\silverback_gutenberg\LinkProcessor;
use Drupal\user\Entity\Role;
use Drupal\user\UserInterface;
use Drupal\Core\Url;
use Drupal\Core\Link;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;

/**
Expand Down Expand Up @@ -325,3 +327,36 @@ function _custom_add_session_iframe_to_page(array &$variables): void {
];
}
}

/**
* Implements hook_preprocess_views_view_field().
*
* Provide the same UX as the core 'content' view for the linked title field.
* As the 'content' view is replaced by the 'moderated_content' one.
*
* - Use the latest revision route if the node has a pending revision.
* - Otherwise, use the canonical node route.
*/
function custom_preprocess_views_view_field(&$variables) {
if (
$variables['view']->id() === 'moderated_content' &&
$variables['field']->field === 'title'
) {
$node = $variables['row']->_entity;
if (!$node || !$node->getRevisionId()) {
return;
}
$langcode = $node->language()->getId();
$rowLangcode = $variables['row']->node_field_revision_langcode;
$translatedNode = $node;
if ($rowLangcode !== $langcode && $node->hasTranslation($rowLangcode)) {
$translatedNode = $node->getTranslation($rowLangcode);
}
/** @var \Drupal\content_moderation\ModerationInformationInterface $moderation_info */
$moderation_info = \Drupal::service('content_moderation.moderation_information');
$url = $moderation_info->hasPendingRevision($translatedNode) ?
Url::fromRoute('entity.node.latest_version', ['node' => $translatedNode->id()]) :
$translatedNode->toUrl();
$variables['output'] = Link::fromTextAndUrl($translatedNode->getTitle(), $url);
}
}

0 comments on commit c55bb4a

Please sign in to comment.