Is there any way to redirect page to homepage if its translated page not found.
Suppose my page url is /en/node/237
, If I switch translation from English to German /ge/node/237
, if it's translated page not found, URL should redirect to homepage of its native language like: /ge/home
Here is my code:
use \Drupal\node\Entity\Node;
$elements = [];
$ids = \Drupal::entityQuery('node')
->condition('type', 'intro_2')
->condition('langcode', 'fr')
->condition('nid',1218)
->execute();
$nodes = Node::loadMultiple($ids);
$language = 'fr';
foreach ($nodes as $node) {
$translation = $node->getTranslation($language);
$elements[] = [
'node' =>$translation->nid->value,
'title' => $translation->title->value,
'url' => $translation->url(),
];
}
dpm($elements);
Above code working fine i have checked on /devel/php,but i am having only following issues:
1)How to get current page node type dynamically in database query
2)How to get current page language dynamically in database query
3)How to get current page node dynamically in database query
Can anyone modify the above code?