26 lines
1.0 KiB
PHP
26 lines
1.0 KiB
PHP
|
<?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);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
?>
|