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
Issue fork entity_print-3531508
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
Comment #3
neograph734Comment #4
jannakha commented- installed entity print on clean D11.2.1
- warning shows up
- applied patch
- no warning after patch
thanks for your contribution!
Comment #5
jannakha commentedthis 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
Comment #6
joseph.olstadThere'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.1Comment #7
jannakha commentedCurrently 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
Comment #8
jsacksick commentedThere is: https://www.drupal.org/project/usage/drupal
Comment #9
joseph.olstadThere is no need to make a new branch.
All we have to do is change entity_print.info.yml
from
^9.4 || ^10 || ^11to
^10.4 || ^11.1Composer 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 || ^11Everyone 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.
Comment #10
tame4tex commentedFrom what I can see on gitlab
\Drupal\Core\Render\RendererInterface::renderRootexisted 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.
Comment #12
jsacksick commentedI 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?
Comment #13
joseph.olstadThanks!
Comment #14
vladimirausThis API is not available for Drupal core 10.2 and earlier so update is required to specify core constrains it in
.info,ymlfile.Comment #15
jsacksick commented@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...
Comment #16
larowlanFolks, let's stay civil here
Comment #17
jsacksick commented@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.