Skip to content
Snippets Groups Projects
Commit e1ab1133 authored by catch's avatar catch
Browse files

Issue #2794261 by longwave, andypost, Oleksiy, Mile23, pguillard, sorlov,...

Issue #2794261 by longwave, andypost, Oleksiy, Mile23, pguillard, sorlov, voleger, jurgenhaas, Chi, borisson_, paulocs, Wim Leers, Berdir: Deprecate render() function in common.inc
parent f563f961
No related branches found
No related tags found
13 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1896Issue #2940605: Can only intentionally re-render an entity with references 20 times,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!512Issue #3207771: Menu UI node type form documentation points to non-existent function,!485Sets the autocomplete attribute for username/password input field on login form.,!449Issue #2784233: Allow multiple vocabularies in the taxonomy filter,!231Issue #2671162: summary text wysiwyg patch working fine on 9.2.0-dev,!43Resolve #3173180: Add UI for 'loading' html attribute to images,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
...@@ -382,11 +382,16 @@ function drupal_attach_tabledrag(&$element, array $options) { ...@@ -382,11 +382,16 @@ function drupal_attach_tabledrag(&$element, array $options) {
* @return * @return
* The rendered element. * 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 \Drupal\Core\Render\RendererInterface
* @see show() * @see show()
* @see hide() * @see hide()
*/ */
function render(&$element) { 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) { if (!$element && $element !== 0) {
return NULL; return NULL;
} }
......
...@@ -70,28 +70,24 @@ function template_preprocess_file_widget_multiple(&$variables) { ...@@ -70,28 +70,24 @@ function template_preprocess_file_widget_multiple(&$variables) {
hide($widget['display']); hide($widget['display']);
} }
hide($widget['_weight']); hide($widget['_weight']);
$widget['_weight']['#attributes']['class'] = [$weight_class];
// Render everything else together in a column, without the normal wrappers. // Render everything else together in a column, without the normal wrappers.
$row = [];
$widget['#theme_wrappers'] = []; $widget['#theme_wrappers'] = [];
$information = \Drupal::service('renderer')->render($widget); $row[] = \Drupal::service('renderer')->render($widget);
$display = '';
// Arrange the row with the rest of the rendered columns.
if ($element['#display_field']) { if ($element['#display_field']) {
unset($widget['display']['#title']); unset($widget['display']['#title']);
$display = [ $row[] = [
'data' => render($widget['display']), 'data' => $widget['display'],
'class' => ['checkbox'], 'class' => ['checkbox'],
]; ];
} }
$widget['_weight']['#attributes']['class'] = [$weight_class]; $row[] = [
$weight = render($widget['_weight']); 'data' => $widget['_weight'],
];
// Arrange the row with all of the rendered columns.
$row = [];
$row[] = $information;
if ($element['#display_field']) {
$row[] = $display;
}
$row[] = $weight;
// Show the buttons that had previously been marked as hidden in this // Show the buttons that had previously been marked as hidden in this
// preprocess function. We use show() to undo the earlier hide(). // preprocess function. We use show() to undo the earlier hide().
......
...@@ -256,11 +256,13 @@ function shortcut_preprocess_page_title(&$variables) { ...@@ -256,11 +256,13 @@ function shortcut_preprocess_page_title(&$variables) {
// Replicate template_preprocess_html()'s processing to get the title in // Replicate template_preprocess_html()'s processing to get the title in
// string form, so we can set the default name for the shortcut. // string form, so we can set the default name for the shortcut.
// Strip HTML tags from the title. $name = $variables['title'];
$name = trim(strip_tags(render($variables['title']))); if (is_array($name)) {
$name = \Drupal::service('renderer')->render($name);
}
$query = [ $query = [
'link' => $link, 'link' => $link,
'name' => $name, 'name' => trim(strip_tags($name)),
]; ];
$shortcut_set = shortcut_current_displayed_set(); $shortcut_set = shortcut_current_displayed_set();
......
name: 'Use render() and check its deprecation'
type: module
description: 'Use render() and check its deprecation.'
package: Testing
version: VERSION
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'
<?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);
}
}
...@@ -931,7 +931,7 @@ protected function createEntityForGroupBy(EntityInterface $entity, ResultRow $ro ...@@ -931,7 +931,7 @@ protected function createEntityForGroupBy(EntityInterface $entity, ResultRow $ro
} }
public function render_item($count, $item) { public function render_item($count, $item) {
return render($item['rendered']); return $this->renderer->render($item['rendered']);
} }
protected function documentSelfTokens(&$tokens) { protected function documentSelfTokens(&$tokens) {
......
<?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()
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment