From 596d078708dbd3960eead889e68352cc3d8715ca Mon Sep 17 00:00:00 2001 From: bach Date: Mon, 2 Aug 2021 19:17:28 +0200 Subject: [PATCH] workarround for samples bug: admin materials inaccessible --- .../SamplesDefaultFormatter.php | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/web/modules/custom/materio_samples/src/Plugin/Field/FieldFormatter/SamplesDefaultFormatter.php b/web/modules/custom/materio_samples/src/Plugin/Field/FieldFormatter/SamplesDefaultFormatter.php index 360331b2..7809c0da 100644 --- a/web/modules/custom/materio_samples/src/Plugin/Field/FieldFormatter/SamplesDefaultFormatter.php +++ b/web/modules/custom/materio_samples/src/Plugin/Field/FieldFormatter/SamplesDefaultFormatter.php @@ -33,23 +33,38 @@ class SamplesDefaultFormatter extends FormatterBase { $term = Term::load($item->target_id); - if(!$term) return; - - // translate the term - $term = \Drupal::service('entity.repository')->getTranslationFromContext($term, $language); + if($term){ + // translate the term + $term = \Drupal::service('entity.repository')->getTranslationFromContext($term, $language); + + $elements[$delta] = [ + // We create a render array to produce the desired markup, + // "

The color code ... #hexcolor

". + // See theme_html_tag(). + '#type' => 'html_tag', + '#tag' => 'span', + '#value' => $this->t('@target : @location', [ + '@target' => $term->getName(), + '@location' => $item->location + ] + ), + ]; + + } else { + $elements[$delta] = [ + // We create a render array to produce the desired markup, + // "

The color code ... #hexcolor

". + // See theme_html_tag(). + '#type' => 'html_tag', + '#tag' => 'span', + '#value' => $this->t('@target : @location', [ + '@target' => "Bug no term available", + '@location' => $item->location + ] + ), + ]; + } - $elements[$delta] = [ - // We create a render array to produce the desired markup, - // "

The color code ... #hexcolor

". - // See theme_html_tag(). - '#type' => 'html_tag', - '#tag' => 'span', - '#value' => $this->t('@target : @location', [ - '@target' => $term->getName(), - '@location' => $item->location - ] - ), - ]; }