Many times the custom logic introduced by a typed entity ends up being used in a preprocess function for rendering. In order to accommodate this we should introduce some opinionated workflow for rendering typed entities.

Requirements:

  1. Acknowledge there are more than one ways to render a typed entity.
  2. Ensure an entity can be interfaced for rendering using drupal's rendering pipeline.
  3. Allow to render a typed entity manually.
CommentFileSizeAuthor
#2 3153900--add-renderers--2.patch14.16 KBe0ipso
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

e0ipso created an issue. See original summary.

e0ipso’s picture

Initial proposal.

e0ipso’s picture

Status: Active » Needs review
hawkeye.twolf’s picture

Wow, this is cool. I think it will really help with separating front-end and back-end business logic.

After a quick review, I have one question/suggestion below but no blockers.

+++ b/src/Render/TypedEntityRendererBase.php
@@ -0,0 +1,63 @@
+    $entity = $wrapped_entity->getEntity();

Could we use WrappedEntityBase::toRenderable() here (after calling WrappedEntityBase::setViewMode())?

e0ipso’s picture

Thanks for the review Hawkeye!

That's a good point you raise. While implementing I got a moment of pause and asked myself: Should renderning an entity change the state of the entity?. For now that's what happens, since (as you already mention) we will need to call WrappedEntityBase::setViewMode().

This is why I think that for now might want to let this idea sit and stay vigilant for the need of it.

  • e0ipso committed c53501b on 2.x
    Issue #3153900 by e0ipso, hawkeye.twolf: Introduce rendering helpers
    
e0ipso’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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