Use Drupal's view builder to render plain content

Created on 28 November 2023, about 1 year ago
Updated 11 December 2023, about 1 year ago

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

Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom scott_euser

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to Closed: won't fix about 1 year ago
  • 🇫🇮Finland j-vee Turku, Finland

    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.

  • 🇬🇧United Kingdom scott_euser

    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

  • Status changed to Active about 1 year ago
  • 🇫🇮Finland j-vee Turku, Finland

    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.

  • 🇫🇮Finland j-vee Turku, Finland

    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.

  • Status changed to Fixed about 1 year ago
  • 🇫🇮Finland j-vee Turku, Finland
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024