Parent issue: #2393329: Replace all drupal_render calls with the service, and inject it, if possible.

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
#18 replace_drupal_render-2471811-18.patch1.21 KBdimaro
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 91,395 pass(es). View
#18 interdiff-2471811-11-18.txt1.24 KBdimaro
#11 replace_drupal_render-2471811-11.patch1.41 KBzaurav
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 91,478 pass(es). View
#9 replace_drupal_render-2471811-9.patch2.66 KBzaurav
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 90,488 pass(es), 550 fail(s), and 308 exception(s). View
#7 replace_drupal_render-2471811-6.patch1.24 KBzaurav
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 90,478 pass(es), 527 fail(s), and 298 exception(s). View

Comments

heddn’s picture

Issue summary: View changes
heddn’s picture

Issue tags: +Twig, +@deprecated, +Novice
heddn’s picture

Issue summary: View changes
cilefen’s picture

heddn’s picture

Issue summary: View changes
cilefen’s picture

Issue summary: View changes
zaurav’s picture

FileSize
1.24 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 90,478 pass(es), 527 fail(s), and 298 exception(s). View
zaurav’s picture

Status: Active » Needs review
zaurav’s picture

FileSize
2.66 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 90,488 pass(es), 550 fail(s), and 308 exception(s). View

Adhering to coding standards. Breaking down 80+char line.

The last submitted patch, 7: replace_drupal_render-2471811-6.patch, failed testing.

zaurav’s picture

FileSize
1.41 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 91,478 pass(es). View

One more time. Last patch had two patches rolled into it.

The last submitted patch, 9: replace_drupal_render-2471811-9.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 11: replace_drupal_render-2471811-11.patch, failed testing.

Status: Needs work » Needs review
Mile23’s picture

Status: Needs review » Needs work
+++ b/core/tests/Drupal/Tests/Core/Render/RendererTest.php
@@ -324,8 +324,9 @@ public function testRenderSorting() {
+    // ensure it remains sorted in the correct order.
+    // \Drupal::service('renderer')->render() will return an empty string if
+    // used on the same array in the same request.

Are we sure this information is correct and relevant? This comment mentions a behavior that doesn't seem to be tested by the test.

keopx’s picture

Assigned: Unassigned » keopx
keopx’s picture

Assigned: keopx » Unassigned
dimaro’s picture

Status: Needs work » Needs review
FileSize
1.24 KB
1.21 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 91,395 pass(es). View

I think the comment is not necessary because the service is not used.

Also I remove "use Drupal\Core\Cache\CacheableDependencyInterface" because not being used.

@Mile23 Do you agree?

webchick’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Needs review » Closed (duplicate)

Thanks @willzyx for all your work on these! Unfortunately, these issues need to be postponed to 8.1.x at least. See the allowed beta changes policy and the comment in #2393329-39: Replace all drupal_render calls with the service, and inject it, if possible..