Skip to content
Snippets Groups Projects

Redirect to www.drupal.org when a node is found, but type is not yet allowed

+ 13
6
@@ -87,12 +87,19 @@ class AllowedContentTypes implements EventSubscriberInterface {
$node = $this->currentRouteMatch->getParameter('node');
if ($node) {
/** @var \Drupal\node\Entity\Node $node */
if (!in_array($node->bundle(), $allowed_types) && !$this->currentUser->hasPermission('bypass node access')) {
$this->messenger->addWarning(t('It is not allowed to edit %type pages in the site yet.', [
'%type' => $node->bundle(),
]));
$response = new RedirectResponse('/');
$event->setResponse($response);
if (!in_array($node->bundle(), $allowed_types)) {
// /i/{nid} redirects through to the aliased URL on www.drupal.org.
$legacy_url = 'https://www.drupal.org/i/' . $node->id();
if ($this->currentUser->hasPermission('bypass node access')) {
$this->messenger->addWarning(t('%type is not fully migrated to new.drupal.org, this is an admin-only preview. <a href=":url">View on www.drupal.org</a>', [
'%type' => $node->bundle(),
':url' => $legacy_url,
]));
}
else {
$response = new TrustedRedirectResponse($legacy_url);
$event->setResponse($response);
}
}
}
Loading