Commit cc13b08a authored by Julian Pustkuchen's avatar Julian Pustkuchen
Browse files

Issue #3307066 by Anybody: Treat NULL as empty

parent 74fe0930
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ class TwigRealContentTwigExtension extends AbstractExtension {
   * @throws \Drupal\twig_real_content\Exceptions\TwigRealContentException
   */
  protected function ensureRendered($value) {
    // @see https://www.drupal.org/project/twig_real_content/issues/3293416
    // The following would allow us to render the content given,
    // but that would lead to hidden performance implications,
    // so until now we decided not to do this.
@@ -93,9 +94,16 @@ class TwigRealContentTwigExtension extends AbstractExtension {
    //   }
    //   return \Drupal::service('renderer')->render($value);
    // }

    // If the value is NULL, return an empty string instead:
    if ($value === NULL) {
      return '';
    }

    if (!is_string($value) && !$value instanceof MarkupInterface) {
      throw new TwigRealContentException('"Twig Has Content Filter" expects rendered strings as value, ' . gettype($value) . ' given. Did you forget to |render / capture the twig variable before?');
    }

    return $value;
  }