Problem/Motivation

Currently an http request is made within ::parseHtml().

Steps to reproduce

N/A

Proposed resolution

Would suggest using Drupal's renderPlain() as used here https://git.drupalcode.org/project/ai_auto_reference/-/blob/1.0.x/src/Ai...

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Comments

scott_euser created an issue. See original summary.

j-vee’s picture

Status: Active » Closed (won't fix)

The issue with renderPlain ends up being is that it doesn't produce the same full HTML page as a HTTP request does and it therefore isn't the right tool here. What I did with the latest release though was that I changed file_get_contents function to use Drupal's HTTP Client service instead.

scott_euser’s picture

As in you want the actual html? Just ::render() instead of renderPlain() should do it maybe? Just needs to be on the right object for the level you want (eg, html, page, node, field level). Essentially if Drupal builds it for the end visitor it should also be able to build it for you without needing to make the http request

scott_euser’s picture

j-vee’s picture

Status: Closed (won't fix) » Active

That solution 2 actually worked. Great suggestion, thanks!

It's a pretty convoluted way of putting the HTML render together. I'll probably make a separate service to handle this to keep things a bit cleaner.

Will include this in a future release so I'll re-open this for now.

j-vee’s picture

Latest update to dev-branch fixes this and there's now a new service that renders a given entity's view mode in HTML. Thanks!

I also generalised the service a bit so that it can now take:

  • Entity type ID
  • Entity ID
  • Revision ID
  • View mode
  • Langcode

I think with those options this module could be extended to do a lot of things.

j-vee’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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