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.
Support from Acquia helps fund testing for Drupal Acquia logo

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

zaurav’s picture

Status: Active » Needs review
zaurav’s picture

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

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

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..