Skip to content
Snippets Groups Projects

Issue #3387229 Check if also an EntityInterface so only entities are included.

1 file
+ 3
1
Compare changes
  • Side-by-side
  • Inline
@@ -2,6 +2,7 @@
namespace Drupal\language_switcher_browser\EventSubscriber;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Routing\TrustedRedirectResponse;
@@ -101,7 +102,8 @@ class LanguageRedirectionSubscriber implements EventSubscriberInterface {
$entity = $this->routeMatch->getParameter('node');
// Check if the entity has translations.
if ($entity && $entity->getEntityTypeId() === 'node' && $entity->hasTranslation($preferred_language)) {
if ($entity && $entity instanceof EntityInterface && $entity->getEntityTypeId() === 'node' && $entity->hasTranslation($preferred_language)) {
// Get the translated node.
$translated_node = $entity->getTranslation($preferred_language);
Loading