#1077148: add an entity-view row plugin added a row plugin to display any supported entity in an unformatted view. I suggest we go one step further and implement a views field handler that is able to display the same rendered entity.

We intend to use this on Commerce to display the line items in the cart: line items are arbitrarily complex entities, we only know that some fields are likely to be there (quantity, price, etc.), we would like to use the rendered entity to render the rest of the fields.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Damien Tournoud’s picture

Status: Active » Needs review
FileSize
3.96 KB

I promised a simple patch. I think it is the case.

fago’s picture

Status: Needs review » Needs work

heureka!

+  public function render($result) {
+    return isset($this->rendered_content[$this->view->row_index]) ? drupal_render($this->rendered_content[$this->view->row_index]) : '';
+  }

I didn't knew about the row_index variable! That helps us a lot for #1172970: provide a unified way to retrieve result entities!

+          'entity_type' => $this->type,

We already have the 'entity type' directly in the 'base table', so there is no need to duplicate it on the field-handler level. Let's make use of the 'base table' level key instead too.

+}
\ No newline at end of file

Minor, but this shouldn't be there.

Indeed, the patch is rather simple and short :)

drunken monkey’s picture

Subscribing.

Damien Tournoud’s picture

Status: Needs work » Needs review
FileSize
4.29 KB

Sorry for dropping the ball on this. Here is a new patch that addresses #2.

fago’s picture

Status: Needs review » Needs work

Thanks, looks good. However, in the meantime #1172970: provide a unified way to retrieve result entities got committed - so I think we should make use of the views_handler_field_entity provided by views now.

fago’s picture

Status: Needs work » Needs review
FileSize
11.68 KB

ok, I've updated the patch to work upon that handler + worked over the entity-row plugin too, so it also makes use of the query-backend's entity loading.

Patch attached. Requires #1270890-13: provide a way to provide entity-related views fields to work.
(It turned out the generic entity-handler misses initialization of $this->entity_type)

das-peter’s picture

subscribe

mh86’s picture

FileSize
12.19 KB

re-rolled patch from #6 for the latest entity api version with following changes:

  • reused the entity_views_handler_field_entity handler for the rendered entity field, which also required a few fixes in this class.
  • renamed 'Entity view' to 'Rendered entity' for consistency
  • fixed warnings in the row plugin in case a field_alias is not available (e.g. Search API)

Changing the name of the row plugin will require a cache clear when updating. In #1330874: Fatal Error Class 'EntityFieldHandlerHelper' not found in entity.views.inc an empty update function has already been added for a similar case, so I think that one should be enough.

fago’s picture

Status: Needs review » Fixed

thanks, committed.

Status: Fixed » Closed (fixed)

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

geek-merlin’s picture

Priority: Normal » Major
Status: Closed (fixed) » Needs work

bumping #1796110: Rendered entity fields show same result
by reopening and raising this issue - the handler seems broken for many use cases.

corvus_ch’s picture

Status: Needs work » Fixed

Working is going on in #1796110: Rendered entity fields show same result. I provided a patch there.

Status: Fixed » Closed (fixed)

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