diff --git a/core/includes/common.inc b/core/includes/common.inc index f640a901219ea24c46857da51b2e459abb37d41d..a9dbc8b44ad924dac5258eb24beb47bc2eeac7f9 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -382,11 +382,16 @@ function drupal_attach_tabledrag(&$element, array $options) { * @return * The rendered element. * + * @deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use + * \Drupal\Core\Render\RendererInterface::render() instead. + * + * @see https://www.drupal.org/node/2939099 * @see \Drupal\Core\Render\RendererInterface * @see show() * @see hide() */ function render(&$element) { + @trigger_error('The render() function is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Render\RendererInterface::render() instead. See https://www.drupal.org/node/2939099', E_USER_DEPRECATED); if (!$element && $element !== 0) { return NULL; } diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc index a3b8868cd0212853e9ac93306b4dac1d05c8677e..15a465e3c3dea8e9c6c6c55764e09714bd4d818c 100644 --- a/core/modules/file/file.field.inc +++ b/core/modules/file/file.field.inc @@ -70,28 +70,24 @@ function template_preprocess_file_widget_multiple(&$variables) { hide($widget['display']); } hide($widget['_weight']); + $widget['_weight']['#attributes']['class'] = [$weight_class]; // Render everything else together in a column, without the normal wrappers. + $row = []; $widget['#theme_wrappers'] = []; - $information = \Drupal::service('renderer')->render($widget); - $display = ''; + $row[] = \Drupal::service('renderer')->render($widget); + + // Arrange the row with the rest of the rendered columns. if ($element['#display_field']) { unset($widget['display']['#title']); - $display = [ - 'data' => render($widget['display']), + $row[] = [ + 'data' => $widget['display'], 'class' => ['checkbox'], ]; } - $widget['_weight']['#attributes']['class'] = [$weight_class]; - $weight = render($widget['_weight']); - - // Arrange the row with all of the rendered columns. - $row = []; - $row[] = $information; - if ($element['#display_field']) { - $row[] = $display; - } - $row[] = $weight; + $row[] = [ + 'data' => $widget['_weight'], + ]; // Show the buttons that had previously been marked as hidden in this // preprocess function. We use show() to undo the earlier hide(). diff --git a/core/modules/shortcut/shortcut.module b/core/modules/shortcut/shortcut.module index 3bdafbbc6b2187cdfac9f2adf49472779af2bf20..50688a67a3f7c15a128ae8cbb6b60bc0e556f1a7 100644 --- a/core/modules/shortcut/shortcut.module +++ b/core/modules/shortcut/shortcut.module @@ -256,11 +256,13 @@ function shortcut_preprocess_page_title(&$variables) { // Replicate template_preprocess_html()'s processing to get the title in // string form, so we can set the default name for the shortcut. - // Strip HTML tags from the title. - $name = trim(strip_tags(render($variables['title']))); + $name = $variables['title']; + if (is_array($name)) { + $name = \Drupal::service('renderer')->render($name); + } $query = [ 'link' => $link, - 'name' => $name, + 'name' => trim(strip_tags($name)), ]; $shortcut_set = shortcut_current_displayed_set(); diff --git a/core/modules/system/tests/modules/render_deprecation/render_deprecation.info.yml b/core/modules/system/tests/modules/render_deprecation/render_deprecation.info.yml new file mode 100644 index 0000000000000000000000000000000000000000..09d7bc9bbd40703358617826a19670d6a151b200 --- /dev/null +++ b/core/modules/system/tests/modules/render_deprecation/render_deprecation.info.yml @@ -0,0 +1,5 @@ +name: 'Use render() and check its deprecation' +type: module +description: 'Use render() and check its deprecation.' +package: Testing +version: VERSION diff --git a/core/modules/system/tests/modules/render_deprecation/render_deprecation.routing.yml b/core/modules/system/tests/modules/render_deprecation/render_deprecation.routing.yml new file mode 100644 index 0000000000000000000000000000000000000000..215f1d6b5728388baa51f0fefa437da69cc05b00 --- /dev/null +++ b/core/modules/system/tests/modules/render_deprecation/render_deprecation.routing.yml @@ -0,0 +1,12 @@ +render_deprecation.function: + path: '/render_deprecation/function' + defaults: + _controller: 'Drupal\render_deprecation\RenderDeprecationController::buildRenderFunction' + requirements: + _access: 'TRUE' +render_deprecation.service: + path: '/render_deprecation/service' + defaults: + _controller: 'Drupal\render_deprecation\RenderDeprecationController::buildRenderService' + requirements: + _access: 'TRUE' diff --git a/core/modules/system/tests/modules/render_deprecation/src/RenderDeprecationController.php b/core/modules/system/tests/modules/render_deprecation/src/RenderDeprecationController.php new file mode 100644 index 0000000000000000000000000000000000000000..cd37c5aa502b410cd1bb9ecec7e4f7a7018fc9ef --- /dev/null +++ b/core/modules/system/tests/modules/render_deprecation/src/RenderDeprecationController.php @@ -0,0 +1,39 @@ +<?php + +namespace Drupal\render_deprecation; + +use Symfony\Component\DependencyInjection\ContainerAwareInterface; +use Symfony\Component\DependencyInjection\ContainerAwareTrait; +use Symfony\Component\HttpFoundation\Response; + +class RenderDeprecationController implements ContainerAwareInterface { + + use ContainerAwareTrait; + + protected function renderArray() { + return [ + 'div' => [ + '#type' => 'container', + '#attributes' => [ + 'id' => 'render-deprecation-test-result', + ], + 'info' => [ + '#markup' => 'Hello.', + ], + ], + ]; + } + + public function buildRenderFunction() { + $build = $this->renderArray(); + $render = render($build); + return Response::create($render); + } + + public function buildRenderService() { + $build = $this->renderArray(); + $render = $this->container->get('renderer')->render($build); + return Response::create($render); + } + +} diff --git a/core/modules/views/src/Plugin/views/field/EntityField.php b/core/modules/views/src/Plugin/views/field/EntityField.php index 7957cb054c8f3a6ab6119c1ba9fbdad26903e028..d3525f4e10425f6d27c575e0c218e7d1974dae16 100644 --- a/core/modules/views/src/Plugin/views/field/EntityField.php +++ b/core/modules/views/src/Plugin/views/field/EntityField.php @@ -931,7 +931,7 @@ protected function createEntityForGroupBy(EntityInterface $entity, ResultRow $ro } public function render_item($count, $item) { - return render($item['rendered']); + return $this->renderer->render($item['rendered']); } protected function documentSelfTokens(&$tokens) { diff --git a/core/tests/Drupal/FunctionalTests/Core/Render/RenderDeprecationTest.php b/core/tests/Drupal/FunctionalTests/Core/Render/RenderDeprecationTest.php new file mode 100644 index 0000000000000000000000000000000000000000..a542006bfd696d6657f862ab65ef82fa7ca49a17 --- /dev/null +++ b/core/tests/Drupal/FunctionalTests/Core/Render/RenderDeprecationTest.php @@ -0,0 +1,46 @@ +<?php + +namespace Drupal\FunctionalTests\Core\Render; + +use Drupal\Tests\BrowserTestBase; +use Drupal\Core\Url; + +/** + * Tests deprecated render() function. + * + * @group Render + * @group legacy + */ +class RenderDeprecationTest extends BrowserTestBase { + + /** + * {@inheritdoc} + */ + protected static $modules = ['render_deprecation']; + + /** + * {@inheritdoc} + */ + protected $defaultTheme = 'stark'; + + /** + * Tests deprecated render() function. + */ + public function testRenderDeprecation(): void { + $this->expectDeprecation('The render() function is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Render\RendererInterface::render() instead. See https://www.drupal.org/node/2939099'); + $id = '#render-deprecation-test-result'; + $this->drupalGet(Url::fromRoute('render_deprecation.function')->getInternalPath()); + /** @var \Behat\Mink\Element\NodeElement $function_render */ + $function_render = $this->getSession()->getPage()->find('css', $id); + + $this->drupalGet(Url::fromRoute('render_deprecation.service')->getInternalPath()); + /** @var \Behat\Mink\Element\NodeElement $service_render */ + $service_render = $this->getSession()->getPage()->find('css', $id); + + $this->assertEquals( + $service_render->getOuterHtml(), + $function_render->getOuterHtml() + ); + } + +}