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 byviews_handler_field_field
.