From 947618f9f749382233b11796675b974c04ce139f Mon Sep 17 00:00:00 2001
From: Nicolas Morand <48729-NicolasGraph@users.noreply.drupalcode.org>
Date: Thu, 28 Mar 2024 12:21:40 +0000
Subject: [PATCH] Avoid multiple unnecessary _gin_get_route_entity() calls

---
 includes/breadcrumb.theme | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/includes/breadcrumb.theme b/includes/breadcrumb.theme
index 3308d5526..9f8cc497b 100644
--- a/includes/breadcrumb.theme
+++ b/includes/breadcrumb.theme
@@ -15,11 +15,11 @@ use Drupal\node\NodeInterface;
 function gin_preprocess_breadcrumb(&$variables) {
   // Alter node breadcrumb.
   if ($variables['breadcrumb']) {
-    foreach ($variables['breadcrumb'] as $key => $item) {
-      $entity = _gin_get_route_entity();
-      $entity_id = $entity ? $entity->getEntityTypeId() : NULL;
-      $url = $entity ? $entity->toUrl() : NULL;
+    $entity = _gin_get_route_entity();
+    $entity_id = $entity ? $entity->getEntityTypeId() : NULL;
+    $url = $entity ? $entity->toUrl() : NULL;
 
+    foreach ($variables['breadcrumb'] as $key => $item) {
       // Back to site item.
       if ($key === 0) {
         $variables['breadcrumb'][$key]['text'] = t('Back to site');
-- 
GitLab