Compare commits
No commits in common. "a14717247fcd7aa3df684a5f7ea177a7b3b2ff6e" and "a4452388cda8871cd995147feb554f01718ff9dc" have entirely different histories.
a14717247f
...
a4452388cd
|
@ -7,6 +7,7 @@ module:
|
||||||
admin_toolbar: 0
|
admin_toolbar: 0
|
||||||
admin_toolbar_links_access_filter: 0
|
admin_toolbar_links_access_filter: 0
|
||||||
advanced_text_formatter: 0
|
advanced_text_formatter: 0
|
||||||
|
alter_routing: 0
|
||||||
audiofield: 0
|
audiofield: 0
|
||||||
autocomplete_deluxe: 0
|
autocomplete_deluxe: 0
|
||||||
ban: 0
|
ban: 0
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
name: 'Alter Routing'
|
||||||
|
type: module
|
||||||
|
description: 'Custom module to alter routing and redirect node/2 to the homepage.'
|
||||||
|
core_version_requirement: ^8 || ^9 || ^10
|
||||||
|
package: Custom
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_preprocess_page().
|
||||||
|
*/
|
||||||
|
function alter_routing_preprocess_page(&$variables) {
|
||||||
|
// Check if the current page is a node page.
|
||||||
|
if (isset($page['#node']) && $page['#node'] instanceof \Drupal\node\NodeInterface) {
|
||||||
|
// Load the front page content directly from its path.
|
||||||
|
$front_page_path = \Drupal::config('system.site')->get('url');
|
||||||
|
$front_page_node = \Drupal\node\Entity\Node::load(\Drupal::entityTypeManager()->getStorage('node')->getQuery()
|
||||||
|
->condition('type', 'page') // Change this to the content type if needed
|
||||||
|
->condition('status', 1)
|
||||||
|
->sort('created', 'DESC')
|
||||||
|
->execute()
|
||||||
|
);
|
||||||
|
|
||||||
|
// If front page content is found, replace node content with front page content.
|
||||||
|
if ($front_page_node) {
|
||||||
|
$view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
|
||||||
|
$rendered_content = $view_builder->view($front_page_node, 'full');
|
||||||
|
$page['content']['#markup'] = \Drupal::service('renderer')->render($rendered_content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
Loading…
Reference in New Issue