Fix Views2 support
mooffie - June 27, 2008 - 06:03
| Project: | Flag |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | closed |
Description
Nate, this patch fixes several problems in our Views2 support.
(The patch isn't really 20K. When I run 'cvs diff' I asked it to include the whole file in the output, because I wanted you to have the whole file before you.)
Main things fixed:
- I removed the:
$join->definition['extra'] = array(
...
array(
'field' => 'content_type',
'alias' => $this->alias,
'value' => $flag->content_type,
'numeric' => FALSE,
),This extra join info was meant to restrict the join to matching content_type's on both sides, but this isn't needed anymore, because the flag ID itself enforces this match (flag_views_flag_config_form() returns only compatible flags). (Besides, variable '$this->alias' didn't exist and gave PHP warning.)
-
The query() method of the relationship handler stored the flags in $views->flags[] but this had several problems:
- If Earl implements query caching, query() most probably won't get a chance to run.
- We accessed this $view->flags[] in the field handler's init(), but since init() executes before query() this array doesn't exist yet.
- No need for this extra storage: It's possible to get to the flag by reaching out to the relationship handler.
So instead I wrote a get_flag() method on the field handler.
- The node's 'type' field was pulled in using 'additional_fields', but this is not possible, because fields registered in this array are linked through the current relationship --which is our flag_content table. Since we haven't told Views how Node connects to this table, linking won't work. So we now pull these fields into the parent relationship.
- $values->nid, and $values->cid were used, in render(), for finding out the content IDs, but these point to the root relationship. Our flaggable content may reside in some other relationship, so, besides the node type above we now also pull in the content ID.
- In the default view ('My bookmarks'), the 'flag_content_rel' relationship must come before the 'uid' one, because the latter uses the former and Views initializes them (that is, calls their set_relationship()) in order. I'm speaking of the '$handler->override_option('relationships', ...)' array.

#1
Here's the patch.
#2
Marked #275028: Fatal error: Cannot access empty property (flag.views.inc) a duplicate of this. (That user's problem is because of point #3.)
#3
I've tested this patch and I can say it resolves my issue (#275028). However, there is another problem: when editing a view relationships and fields show up twice.
I am not sure if I should open a new issue on this but it would be useful if in the relationship configuration you could choose multiple flags and if there was a field that could print all of them. It would save users a lot of time. Currently you have to configure individual relationships and fields for each of the flags.
#4
(I don't understand this sentence. I'll assume your following paragraph, which I do understand, is an explanation of the above. So I'll ignore the above.)
If I understand correctly, what you're asking for is operation akin to that of the Drupal 5 version of this module. In the D5 version you have to click only 10 times (not really, but sort of) to include 10 'Ops' fields in the view. ('ops' is our nickname for the flag links.)
On the other hand, if it's 10 'Ops' fields that you want, then you can simply use the 'Node' row style and you won't even have to click 10 checkboxes, because all 'Ops' are in the node links.
Nate, what are your thoughts on this?
#5
(See you next week. As for the new discussion: I'd suggest, before we discuss it further, that we commit my patch because the current V2 support doesn't really work. Perhaps it worked in previous Views beta, but seemingly not in the latest(s) release(s).)
#6
tracking
I don't know if i need open a new bug but:
In the filter for view2 they have:
Flags: Flagged
Filter to ensure a node has or has not been flagged.
Flags: Flagged time
Display the time the node was flagged by a user.
But what don't have another filter :
Flags: user id
Display the node flagged by this user
#7
The patch worked for me too. I can view "My Bookmarks" now. :-)
#8
archetwist, in comment #3, writes:
I've opened a new issue to address your concerns.
#9
This isn't realy a bug, but I opened a new issue: #276899: Missing "UID" argument
#10
This looks great to me. Thanks for figuring out a way to find that flag option everywhere moofie! I ended up creating the $view->flags array after getting fed up trying to navigate the view object. Thanks for fixing that ->nid/cid reference too, again, I simply couldn't find the appropriate place to pull the field aliases from.
#11
Great, so we can close this.
(archetwist and gagarine: I opened seperate issues for the points you raised.)
Fortunately, V2 has a nice trait: handlers can reach out to other handlers. (A nice example is the way the 'depth' taxonomy argument works: it modifies the previous argument.)
#12
Automatically closed -- issue fixed for two weeks with no activity.