Problem/Motivation

drupal_render() was marked as deprecated, though its still called in quite some places.

Proposed resolution

  1. Avoid rendering manually by letting the template who is printing the variable render it.
  2. Inject the renderer service into service, which uses drupal_render()
  3. Use \Drupal::service('renderer')->render() for old prodecural code.

Remaining tasks

  1. Find all the actionable fixes: Search for drupal_render(
  2. Create a Patch
  3. Review

User interface changes

None

API changes

None

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because this removes usages of a deprecated function.
Issue priority Not critical because the function in question is not to be removed in this release cycle.
Files: 
CommentFileSizeAuthor
#4 drupal-scripts-drupal_render-replacement-2471853-4.patch906 bytesnicoloye
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 91,433 pass(es). View
#2 drupal-scripts-drupal_render-replacement-2471853-2.patch937 bytesnicoloye
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 91,531 pass(es). View

Comments

nghai’s picture

Component: token system » theme system
nicoloye’s picture

Status: Active » Needs review
FileSize
937 bytes
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 91,531 pass(es). View

Here is a patch for the needed replacement.

Mile23’s picture

Status: Needs review » Needs work
+++ b/core/scripts/run-tests.sh
@@ -1204,7 +1204,7 @@ function simpletest_script_open_browser() {
+  $html = '<head>' . \Drupal::service('renderer')->render($js_assets_header) . \Drupal::service('renderer')->render($css_assets) . '</head><body>' . \Drupal::service('renderer')->render($form) . \Drupal::service('renderer')->render($js_assets_footer) .'</body>';

Why not grab the renderer once and then re-use it? Then \Drupal doesn't have to resolve the service over and over.

  $renderer = \Drupal::service('renderer');
  $html = '<head>' . $renderer->render($js_assets_header) . ... etc...
nicoloye’s picture

Status: Needs work » Needs review
FileSize
906 bytes
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 91,433 pass(es). View

Right, that's much better, thanks for the advice :)

ezcleanup’s picture

Its quite better

Mile23’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs beta evaluation

Ah we love our two line patches. :-)

Added beta evaluation.

dimaro’s picture

Is it necessary need a space to concatenate the variable with the tag ''?

+  $html = '<head>' . $renderer->render($js_assets_header) . $renderer->render($css_assets) . '</head><body>' . $renderer->render($form) . $renderer->render($js_assets_footer) .'</body>';
xjm’s picture

Assigned: nghai » Unassigned
Status: Reviewed & tested by the community » Closed (duplicate)

Thanks for your work on this issue! Per discussion with @alexpott and @webchick, we should do these conversions in a single patch in #2393329: Replace all drupal_render calls with the service, and inject it, if possible.. The change will need to be postponed to 8.1.x at least since it is no longer an allowed change during the Drupal 8 beta. See #2393329-39: Replace all drupal_render calls with the service, and inject it, if possible..