Problem/Motivation

Attempting to render a pdf on Drupal 11.2 throws the following error:

User notice: Drupal\Core\Render\Renderer::render with $is_root_call is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use Drupal\Core\Render\Renderer::renderRoot() instead. See https://www.drupal.org/node/3497318.

No PDF is generated.

Relevant change record: https://www.drupal.org/node/2511330

Steps to reproduce

Update to Drupal 11.2 and attempt to download a PDF with an existing link.

Proposed resolution

Update Drupal\entity_print\Renderer\RenderBase to use renderRoot instead of render():

/**
   * {@inheritdoc}
   */
  public function generateHtml(array $entities, array $render, $use_default_css, $optimize_css) {
    $rendered_css = $this->assetRenderer->render($entities, $use_default_css, $optimize_css);
    $render['#entity_print_css'] = $this->renderer->executeInRenderContext(new RenderContext(), function () use (&$rendered_css) {
      return $this->renderer->render($rendered_css);
    });

    $html = (string) $this->renderer->executeInRenderContext(new RenderContext(), function () use (&$render) {
//      return $this->renderer->render($render, TRUE);  OLD LINE.
      return $this->renderer->renderRoot($render); // NEW LINE.
    });

    // Allow other modules to alter the generated HTML.
    $this->dispatcher->dispatch(new PrintHtmlAlterEvent($html, $entities), PrintEvents::POST_RENDER);

    return $html;
  }

Remaining tasks

Tag a D11.2 compatible release?

User interface changes

None

API changes

None

Data model changes

None

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

neograph734 created an issue. See original summary.

neograph734’s picture

Status: Active » Needs review
jannakha’s picture

Status: Needs review » Reviewed & tested by the community

- installed entity print on clean D11.2.1
- warning shows up
- applied patch
- no warning after patch

thanks for your contribution!

jannakha’s picture

this may break old versions of Drupal (10.3 and under)
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21...

Will be released as part of 3.x

joseph.olstad’s picture

There's currently no 3.x branch.

10.4 , 11.1/11.2 are current.

10.3 is not current.

Easier solution is to update the .info.yml file rather than new branch

^10.4 || ^11.1

jannakha’s picture

Currently it’s
9.4^ || 10^ || 11^

There will be more D11 compatibility issues coming

There’s no visibility of how many Drupal 9-10.3 installations still out there

Will be good to move on to proper versioning

jsacksick’s picture

There’s no visibility of how many Drupal 9-10.3 installations still out there

There is: https://www.drupal.org/project/usage/drupal

joseph.olstad’s picture

There is no need to make a new branch.

All we have to do is change entity_print.info.yml

from
^9.4 || ^10 || ^11

to

^10.4 || ^11.1

Composer will then ensure that those running ^9.4 or 10.0/10.1/10.2/10.3 will get the most recent release that has
^9.4 || ^10 || ^11

Everyone with 10.4 || 11.1 will get the fix that we publish in a new release. There's no need for a new branch to protect someone with 9.4 or 10.0.

Far too many projects are unnecessarily creating new branches/tagging new majors for supporting current releases of Drupal

composer does the work, we just have to play ball.

tame4tex’s picture

From what I can see on gitlab \Drupal\Core\Render\RendererInterface::renderRoot existed in 9.4.0 (see https://git.drupalcode.org/project/drupal/-/blob/9.4.0/core/lib/Drupal/Core/Render/RendererInterface.php?ref_type=tags). Is this an assumption it wont work or has it been confirmed?

This bug is also causing test failures on other issues which creates a lot of unnecessary noise (e.g. #3019791: Allow setting target attribute on EntityPrintViewsLink area handler).

+1 for not requiring a new branch to expedite the release of the fix. Paragraphs is an example of a very populate module that drops support for Drupal versions in a minor release.

jsacksick’s picture

Status: Reviewed & tested by the community » Fixed

I don't see why a new branch is required... If all we do is calling renderRoot which kinda always existed (it was added 10 years ago)... So I think we can just merge this?

joseph.olstad’s picture

Thanks!

vladimiraus’s picture

Version: 8.x-2.16 » 8.x-2.x-dev
Status: Fixed » Needs work

This API is not available for Drupal core 10.2 and earlier so update is required to specify core constrains it in .info,yml file.

jsacksick’s picture

Status: Needs work » Fixed

@vladimiraus: Did you miss comment #10?

renderRoot() has been around for 10 years? What am I missing?

See https://git.drupalcode.org/project/drupal/-/blob/9.4.0/core/lib/Drupal/C...

It even existed in Drupal 8: See https://git.drupalcode.org/project/drupal/-/blob/8.0.x/core/lib/Drupal/C...

larowlan’s picture

Folks, let's stay civil here

jsacksick’s picture

@larowlan: I apologize if that came off the wrong way — I genuinely didn't mean to be offensive. I'm just trying to understand what I might be missing.
Also FYI I worked on this as this was causing the Commerce Invoice tests to fail.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.