Commit 9ccb44e2 authored by catch's avatar catch
Browse files

Issue #2501931 by alexpott, alimac, cmanalansan, davidhernandez, scotself,...

Issue #2501931 by alexpott, alimac, cmanalansan, davidhernandez, scotself, cilefen, RavindraSingh, peezy, YesCT, pwolanin: Remove SafeMarkup::set in twig_render_template() and ThemeManager and FieldPluginBase:advancedRender
parent 5fcb2db3
Loading
Loading
Loading
Loading
+2 −2
Changes for core/lib/Drupal/Core/Render/Renderer.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -518,7 +518,7 @@ protected function doRender(&$elements, $is_root_call = FALSE) {
    $prefix = isset($elements['#prefix']) ? $this->xssFilterAdminIfUnsafe($elements['#prefix']) : '';
    $suffix = isset($elements['#suffix']) ? $this->xssFilterAdminIfUnsafe($elements['#suffix']) : '';

    $elements['#markup'] = $prefix . $elements['#children'] . $suffix;
    $elements['#markup'] = SafeString::create($prefix . $elements['#children'] . $suffix);

    // We've rendered this element (and its subtree!), now update the context.
    $context->update($elements);
@@ -553,7 +553,7 @@ protected function doRender(&$elements, $is_root_call = FALSE) {
    $context->bubble();

    $elements['#printed'] = TRUE;
    return SafeString::create($elements['#markup']);
    return $elements['#markup'];
  }

  /**
+7 −3
Changes for core/lib/Drupal/Core/Theme/ThemeManager.php: 7 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -7,12 +7,13 @@

namespace Drupal\Core\Theme;

use Drupal\Component\Utility\SafeStringInterface;
use Drupal\Core\Render\SafeString;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Routing\StackedRouteMatchInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Template\Attribute;
use Drupal\Component\Utility\SafeMarkup;

/**
 * Provides the default implementation of a theme manager.
@@ -317,7 +318,10 @@ public function render($hook, array $variables) {
    $output = '';
    if (isset($info['function'])) {
      if (function_exists($info['function'])) {
        $output = SafeMarkup::set($info['function']($variables));
        // Theme functions do not render via the theme engine, so the output is
        // not autoescaped. However, we can only presume that the theme function
        // has been written correctly and that the markup is safe.
        $output = SafeString::create($info['function']($variables));
      }
    }
    else {
@@ -387,7 +391,7 @@ public function render($hook, array $variables) {
      $output = $render_function($template_file, $variables);
    }

    return (string) $output;
    return ($output instanceof SafeStringInterface) ? $output : (string) $output;
  }

  /**
+2 −2
Changes for core/lib/Drupal/Core/Theme/ThemeManagerInterface.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -26,8 +26,8 @@ interface ThemeManagerInterface {
   * @param array $variables
   *   An associative array of theme variables.
   *
   * @return string
   *   The rendered output.
   * @return string|\Drupal\Component\Utility\SafeStringInterface
   *   The rendered output, or a SafeString object.
   */
  public function render($hook, array $variables);

+2 −2
Changes for core/modules/comment/src/Tests/Views/CommentFieldNameTest.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -91,11 +91,11 @@ public function testCommentFieldName() {
    $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
      return $view->field['field_name']->advancedRender($view->result[0]);
    });
    $this->assertIdentical($this->comment->getFieldName(), $output);
    $this->assertEqual($this->comment->getFieldName(), $output);
    $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
      return $view->field['field_name']->advancedRender($view->result[1]);
    });
    $this->assertIdentical($this->customComment->getFieldName(), $output);
    $this->assertEqual($this->customComment->getFieldName(), $output);
  }

}
+4
Changes for core/modules/serialization/serialization.services.yml: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -30,6 +30,10 @@ services:
      arguments: ['Drupal\Core\Field\Plugin\Field\FieldType\PasswordItem']
      tags:
        - { name: normalizer, priority: 20 }
  serializer.normalizer.safe_string:
      class: Drupal\serialization\Normalizer\SafeStringNormalizer
      tags:
        - { name: normalizer }
  serializer.normalizer.typed_data:
    class: Drupal\serialization\Normalizer\TypedDataNormalizer
    tags:
Loading