Problem/Motivation

If I use entity fields as output and enable grouping in some occasions I get notices about undefined indexes and broken field output.
Some of these notices can be avoided by adding extra grouping fields in the Aggregation settings of a field.
E.g on a text field you can include "Format" to ensure this field value item is available for later use.
Unfortunately there are some "hidden" field value items e.g. "safe_value" on text fields. Those "hidden" field value items currently aren't addressed by views_handler_field_field.

Those "hidden" field value items are handled by hook_field_load and hook_field_attach_load.
These hooks are fired whenever an entity is loaded.
If aggregation is used views_handler_field_field modifies the field item values, to inject the views specific field output, of the returned entities.
Doing so the field item values are overwritten completely - and thus everything that's not explicitely declared in the Aggregation settings is lost.
The in code documentation says:

// Note: We would copy original values here, but it can cause problems.
// For example, text fields store cached filtered values as
// 'safe_value' which doesn't appear anywhere in the field definition
// so we can't affect it. Other side effects could happen similarly.

Proposed resolution

As disscues with dereine via IRC we should fire hook_field_load and hook_field_attach_load once the field item values are overwritten, to maintain the "hidden" field item values.
dereine already proposed a solution: http://paste.pocoo.org/show/540775/
The attached patch tries to take care about the // @todo: This hook should actually use the multiple execution.
To do so quite a bit of the post processing in views_handler_field_field was changed, including a function signature.

Remaining tasks

  • Definitely needs a good review and heavy testing to ensure nothing bad is introduced.
    Latest patch #1
  • Define an upgrade strategy - the fact that Entity API breaks with this patch shows how tricky this change is. See #1
  • Define what has to happen with multi-value fields when aggregation is used. See #1.

User interface changes

None

API changes

  • views_handler_field_field::set_items()
    Accepted parameters changed from ($values, $row_id) to ($entity_type, $entity, $display).
    Return is the same as before.
    In views itself this method is used just internally by views_handler_field_field.

Comments

das-peter’s picture

I've just figured out that:

  1. Multi value fields only return a single value when aggregation is used, even if multiple values are requested. The updated patch skips the field value modification for such fields - but I really don't know if this is the best solution.
  2. The views integration of Entity API uses views_handler_field_field::set_items(). A patch to make it working with the new function signature is added.
das-peter’s picture

Issue summary: View changes

Updated issue summary.

dawehner’s picture

Changing something in this file actually should require some test coverage as this is really a major functionality of views.
Here is an issue with the testing, though you can't say it's started yet.
#722172: Write tests for the field integration

tim.plunkett’s picture

Triggering the testbot.

Status: Needs review » Needs work

The last submitted patch, entity-views-integration-update-for-views-change-1417520.patch, failed testing.

yang_yi_cn’s picture

the first patch in #1 fixes my problem, which is:

- I have content which has references to Photo (entity)
- Photo entity has an image field
- I ran an aggregation based on location (lat/lng) of the content instead of node id
- the image path is suppose to be pulled using Node > Photo > Image relationship.

without the patch, the image path will only show the image style directory but not the actually file name. With the patch it works.

I do experience a side effect in Link module, though I think it's Link module's problem that didn't expect that _load will be called in other than node_load. I supplied a patch to Link module in http://drupal.org/node/1374928#comment-7080876

Exploratus’s picture

I have the same problem with images as stated in #5. Will test patch.

Exploratus’s picture

#1 worked for me. as soon as I applied the patch, my images (image cache) started showing up on the aggregated view. The url string was broken before as stated in #5, but now i dodnt get duplicate content AND I can see the images. YAY!

I am not sure this is the correct approach, but at least it works in the meantime, until a better patch is worked through,

das-peter’s picture

das-peter’s picture

Issue summary: View changes

Updated issue summary.

valthebald’s picture

It looks like patch doesn't apply anymore (hunk #3 fails)

shashwat purav’s picture

#1 Worked for me. :)

laVera’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new6.09 KB

1. For users:
The last patch wasn't working for current 7.x-3-dev; Here is one working.

2. For the maintainers:
This is a 3 years old bug, what do you need to commit?

dawehner’s picture

This is a 3 years old bug, what do you need to commit?

You know, committing is the easy part, but actually thinking about it, is the hard part. What does that mean, if you commit this patch.
The additional hook fired might lead to NETTO more bugs than we fix with this particular commit. Maybe most hook_field_load()
implementations don't think about non actual entities and do something bad with it. Would be nice to have some kind of research or general statement about it.

laVera’s picture

Thanks dawwehner!

I'm not sure what you mean by NETTO but I guess is something like "net total".....

I understand this change may break some other modules, and they will need upgrades. But my point is that this a mayor usage bug:
It break images on products display views, where you do relation ship to ensure product variants are available. Then for less technical site builder, they will go to magento, pimcore or another non Drupal alternative :(

Then, I understand that dev versions are precisely for this kind of think....I don't see a problem with a dev module breaking other modules for fix an own bug, that why is it's dev.

I'm committed to Drupal promotion, but this kind of thing are hinders for new adoption. Please let me know if there is something that I could to help as general user (I have no idea what hook_field_load() do)

colan’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 7.x-3.x-dev » 8.1.x-dev
Component: fieldapi data » views.module
Status: Reviewed & tested by the community » Needs work

I'm not convinced we should be making these API changes in D7 just yet. Let's get this figured out in D8 first, and then backport if desired.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

pancho’s picture

Issue tags: +views aggregation

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

catch’s picture

Status: Needs work » Closed (outdated)

This is no longer an issue in Drupal 9, there aren't hook_field_load() hooks to trigger separately from field rendering.