Commit 978a8bf8 authored by catch's avatar catch
Browse files

Issue #3299946 by longwave, Spokje: Deprecate theme_render_and_autoescape()

parent 2fbac34e
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -344,13 +344,14 @@ function theme_get_setting($setting_name, $theme = NULL) {
 * @throws \Exception
 *   Thrown when an object is passed in which cannot be printed.
 *
 * @see \Drupal\Core\Template\TwigExtension::escapeFilter()
 * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no
 *   replacement. Theme engines must handle escaping by themselves.
 *
 * @todo Discuss deprecating this in https://www.drupal.org/node/2575081.
 * @todo Refactor this to keep it in sync with Twig filtering in
 *   https://www.drupal.org/node/2575065
 * @see https://www.drupal.org/node/3336253
 */
function theme_render_and_autoescape($arg) {
  @trigger_error('theme_render_and_autoescape() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. Theme engines must handle escaping by themselves. See https://www.drupal.org/node/3336253', E_USER_DEPRECATED);

  // If it's a renderable, then it'll be up to the generated render array it
  // returns to contain the necessary cacheability & attachment metadata. If
  // it doesn't implement CacheableDependencyInterface or AttachmentsInterface
+1 −2
Original line number Diff line number Diff line
@@ -760,8 +760,7 @@ function hook_extension() {
 * It is the theme engine's responsibility to escape variables. The only
 * exception is if a variable implements
 * \Drupal\Component\Render\MarkupInterface. Drupal is inherently unsafe if
 * other variables are not escaped. The helper function
 * theme_render_and_autoescape() may be used for this.
 * other variables are not escaped.
 *
 * @param string $template_file
 *   The path (relative to the Drupal root directory) to the template to be
+0 −6
Original line number Diff line number Diff line
@@ -387,9 +387,6 @@ public function escapePlaceholder(Environment $env, $string) {
   *
   * Replacement function for Twig's escape filter.
   *
   * Note: This function should be kept in sync with
   * theme_render_and_autoescape().
   *
   * @param \Twig\Environment $env
   *   A Twig Environment instance.
   * @param mixed $arg
@@ -408,9 +405,6 @@ public function escapePlaceholder(Environment $env, $string) {
   * @throws \Exception
   *   When $arg is passed as an object which does not implement __toString(),
   *   RenderableInterface or toString().
   *
   * @todo Refactor this to keep it in sync with theme_render_and_autoescape()
   *   in https://www.drupal.org/node/2575065
   */
  public function escapeFilter(Environment $env, $arg, $strategy = 'html', $charset = NULL, $autoescape = FALSE) {
    // Check for a numeric zero int or float.
+2 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
 * Handles integration of Nyan cat templates because we love kittens.
 */

use Drupal\Component\Utility\Html;
use Drupal\Core\Extension\Extension;

/**
@@ -36,7 +37,7 @@ function nyan_cat_render_template($template_file, $variables) {
  $output = str_replace('div', 'nyancat', file_get_contents(\Drupal::root() . '/' . $template_file));
  foreach ($variables as $key => $variable) {
    if (strpos($output, '9' . $key) !== FALSE) {
      $output = str_replace('9' . $key, theme_render_and_autoescape($variable), $output);
      $output = str_replace('9' . $key, Html::escape($variable), $output);
    }
  }
  return $output;
+9 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
 * Tests the theme_render_and_autoescape() function.
 *
 * @group Theme
 * @group legacy
 */
class ThemeRenderAndAutoescapeTest extends KernelTestBase {

@@ -27,6 +28,14 @@ class ThemeRenderAndAutoescapeTest extends KernelTestBase {
   */
  protected static $modules = ['system'];

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();
    $this->expectDeprecation('theme_render_and_autoescape() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. Theme engines must handle escaping by themselves. See https://www.drupal.org/node/3336253');
  }

  /**
   * @dataProvider providerTestThemeRenderAndAutoescape
   */