Needs work
Project:
Virtual Field
Version:
7.x-1.0
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
28 Mar 2012 at 13:03 UTC
Updated:
20 Aug 2015 at 07:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
xen commentedvirtual_field_handler_field_virtual_field.inc seems to be missing from the patch?
Views support would be so nice.
Comment #2
batje commentedHere is another version, including all data, and including searchAPI supprt (so virtual fields also can be rendered on views based on SearchAPI)
Comment #3
xen commentedI get broken handler when trying to use this field?
Not too fond of the fact that it seems to be loading each entity individually instead of using entity_load with an array of ids. It's a bit of a performance killer. There also seems do be a lot of magic around Search API. Why is that? I thought the idea behind using search API views was to hide the fact that it was a search. If they're really that different, having separate handlers for entity views and search API views might be a better solution.
What's going on here?:
+ // Only pass a single item to the formatter_view hook. Feel free to build a foreach here, we had issues
+ // with the key that was returned. The documentation says it should be 0, 1, 2 etc but we had to put in
+ // a certain string.
Also, it seems to be one views field where one can select a virtual field to render. Like date modules odd handling of fields. I'd rather have a handler that provides multiple views fields, like the field module.
Comment #4
batje commentedIn general, we went step by step getting the thing to do what we need, based on the virtual_field, this code and a custom virtual_field with a formatter we wrote. It's all pretty new to use, fields + ctools + views 3.0 + searchAPI, so this is how far we got. And yes, it doesnt win a beauty contest.
- Not sure why you get a broken handler, what does your syslog or apachelog say?
- SearchAPI's basetable & related things are very different from the standard node one. As we need to manually load the entity (all at the same time, or one by one) we need to get the information from somewhere else, depending on the type of query the view is based on. Not sure if we would need a 'Virtual SearchAPI' Field and a 'Virtual standard' field. Rather have ugly code than the user realizing what is going on.
- Not sure where a field-handler would load all entities into a views result.
- What was going on was that the documentation for formatter_view says the return value should be a keyed array with numeric keys. Whenever we did that, we had issues. Our virtualfield returns an array with key 'links'. That worked. This is a (improvable) comment about that. And surely someone smarter than use will be able to solve.
- Am not sure how the multi-field views thing would work.
Basically, this, for now, is the best we could do. Its not much, but it can work. We used it to make the contextual menus and the tabs (edit, devel etc) of a node show up in a ctools dropdown button, and to show a progressbar of our editing process as well.
We'll surely add improvements when we find issues in our configuration, but would be glad if others can help improving this patch.
Comment #5
batje commentedindeed, the changes to the info file were not included in the patch.
Comment #6
xen commentedThe latest patch is empty?
Hey, it's a start. You should see some of my first drafts...
Well, the field handler does it, so it should be possible... But it does require figuring out what's going on here: http://drupalcode.org/project/views.git/blob/423bc82111925528f00838bd200...
Sniffing about SearchAPI code (http://drupalcode.org/project/search_api.git/blob/bfc5f152b1956008940664...) it does seem to add the entity type to the information passed to views, as does Views (http://drupalcode.org/project/views.git/blob/423bc82111925528f00838bd200... for instance), so it would be a much safer bet to get that information from views (how, I don't know off-hand), than relying on parsing the base table (which might not map up to a entity type). That might actually eliminate the need for special SearchAPI handling.
Sounds odd. And just looking at the code, there seems to be something wrong, but I don't know what. But you shouldn't be calling the formatter hooks directly, but use field_view_value() which should do most of the heavy lifting for you.
A pre_render method, I guess. Apparently it gets the full resultset prior to rendering: http://drupalcode.org/project/views.git/blob/423bc82111925528f00838bd200... , it should then load all the entities and cache them in the object for the render method to pick out.
Comment #7
Jan van Diepen commentedRedid the intended patch with the changes to the .info file included.
Also fixed a php warning:
Comment #8
Jan van Diepen commentedChanged status from needs work to needs review.
Comment #9
Jan van Diepen commentedCreated a new patch with the following notices fixed.
Comment #10
xen commentedSo it's basically fully loading the entities. I can't imagine that views does that for fields in general.
This code shouldn't define a language. I guess field_language() should be used.
This is rather low level. Something like field_view_value() seems a better option.
Odd comment.
Is this really the only way of detecting Search API?
Comment #11
Jan van Diepen commentedMade the code a little bit more robust.
Here's a new patch.
Comment #12
xen commentedI'm still hoping that there's a better way to find the entities than this, preferably avoiding having to have special handling for search_api. Else we need more defensive coding that checks whether we really get a proper entity type.
I've still not gotten a good explanation why we need all this, rather than a simple field_view_field() or field_view_value().
This is still lazy. We should be able to figure out which virtual fields exists and only add existing fields to the relevant base tables. Views build-in field support does it, so should we.
Comment #13
Joanna_Kisaakye commentedI noticed that the patch from #11 was not compatible with field_collection_item entities that use the field name as the name of the bundle, therefore I updated the patch in #11 to that effect.
Comment #15
Joanna_Kisaakye commentedI fixed the typo in my last patch
Comment #16
Joanna_Kisaakye commentedComment #21
batje commentedJoanna, if you review the test, you can see that the patch does not apply correctly.
Did you base the patch on the raw 7.x-1.0 dev branch or on the 7.x-1.2 stable version?
Comment #22
xen commentedI would prefer if someone would address my reservations above rather than rerolling.
Comment #23
Joanna_Kisaakye commentedBatje, I based my patch on the current 7.x-1.x branch