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
......@@ -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;
}
......
......@@ -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().
......
......@@ -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();
......
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
}
public function render_item($count, $item) {
return render($item['rendered']);
return $this->renderer->render($item['rendered']);
}
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()
);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment