The data-selection based views fields don't add the entity-id to the query, different to what the comment says:

  /**
   * Add the field for the entity ID (if necessary).
   */
  public static function query($handler) {
    // Some of the parent handlers might require this.
    $handler->field_alias = $handler->real_field;
    $handler->base_field = self::get_selector_field_name($handler->real_field);
  }

We should probably take that part over from the views entity field handler.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fago’s picture

Status: Active » Needs review
FileSize
8.44 KB

ok, attached is a fix.

When copying over the code I noted we are using already a 'base_field' property, such as views but with another meaning.. :/ That's bad and would have resulted in a clash in the helpers query() method, so I've removed that invented base_field as it doesn't appear to be often used anyway.

Tested attached patch - it fixes the bug. Misses search api views integration test, though I've looked it up and it doesn't seem to make use of that base_field. Anyway, please test.

mh86’s picture

Status: Needs review » Reviewed & tested by the community

tested the patch on 2 websites with pretty complex views and everything still seems to work.

drunken monkey’s picture

Status: Reviewed & tested by the community » Needs work

Fatal errors and completely messed-up display – please don't commit yet!

fago’s picture

>Fatal errors and completely messed-up display – please don't commit yet!

ok, waiting for more feedback on what's wrong...

drunken monkey’s picture

First off, the attached patch fixes a stray self::get_selector_field_name() in entity_views_handler_field_options which leads to fatal errors when displaying a view which uses that field handler.

Secondly, but – as I see now – unrelated to this, commit e29298c messed up entity_views_handler_field_entity. The entity now always uses the entity type of the current view, not of the referenced field. So, e.g., when I have a node search displaying the nodes' tags, and a node has a tag with the tid 1, then a link to the node with NID 1 is displayed.
This has definitely got to be fixed before any stable release.

mh86’s picture

Status: Needs work » Needs review
FileSize
9.21 KB

Reverted the entity_views_handler_field_entity handler to use the field's entity type instead of the current view's entity type. Additionally added the entity type information to the new entity field handler that was added in #1209678: Add a Views field handler to display rendered entities.
Furthermore, I was wondering if there is still something in common between entity_views_handler_field_entity and views_handler_field_entity?

fago’s picture

thanks, renewed the patch. I've removed the entity type from the definition, as having type and entity type there is kind of duplicated. Instead, it's initialized during init().

Furthermore, I was wondering if there is still something in common between entity_views_handler_field_entity and views_handler_field_entity?

Good point, changed that.

Please test.

mh86’s picture

from my point of view, this is ready (tested it with some views), but I'm leaving it up to Thomas to mark it as RTBC.

drunken monkey’s picture

Status: Needs review » Needs work

Nope, sorry, it still has the mentioned (second) problem.

drunken monkey’s picture

EntityFieldHandlerHelper::pre_render() resets $handler->entity_type back to the wrong type.

This is caused by you calling get_result_entities() without relationship, thereby of course setting the type back to the base entities'. I don't really know why you made that change in the other issue in the first place, so I can't really tell how to best fix this.
From what I can see, we could either override entity_views_handler_field_entity::pre_render() with a slightly modified version of EntityFieldHandlerHelper::pre_render(); or we could make the behaviour of the third parameter to get_result_entities() (and get_result_wrappers()) a requirement and just append ':entity object' to the handler's $real_field property.

fago’s picture

Hm, partly I think $handler->entity_type is populated wrong as get_result_wrappers() returns the wrappers type. Maybe we should just use $handler->type or $handler->data_type else?

I don't think we need to populate $handler->entity_type unless for the entity handler, where we can then make sure it's right one. Thoughts?

drunken monkey’s picture

I don't think we need to populate $handler->entity_type unless for the entity handler, where we can then make sure it's right one. Thoughts?

I don't think that's true, as the property is used for all handlers in the EntityFieldHandlerHelper::render_entity_link() method. Or am I misunderstanding you there?

Basically, as said, I don't know why you changed it in the first place, so I can't really say what fix would be appropriate or the best. Otherwise, we could just revert the changes that introduced the bug.

fago’s picture

Status: Needs work » Needs review
FileSize
13.63 KB

uhm, sry forget #11 - I was wrong.

Basically, as said, I don't know why you changed it in the first place, so I can't really say what fix would be appropriate or the best. Otherwise, we could just revert the changes that introduced the bug.

Indeed, instead I worked on fixing that by introducing a $field_entity_type and improved docs on to which entity $entity_type belongs. See attached patch.

I tested rendering the node:author, what worked . Even for anonymous authors! :D

drunken monkey’s picture

Status: Needs review » Reviewed & tested by the community

Great job, seems to work fine for me. (Didn't test everything, though, so I'll just trust you didn't mess up anything else now. ;P)

mh86’s picture

looks good to me as well

fago’s picture

Status: Reviewed & tested by the community » Fixed

Committed :)

Status: Fixed » Closed (fixed)

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