Closed (won't fix)
Project:
Flag
Version:
6.x-1.1
Component:
Flag core
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
6 May 2009 at 21:41 UTC
Updated:
4 Oct 2009 at 02:39 UTC
I wanted a way to grab the Flag data about a node when I loaded the node. Four lines did it in the nodeapi hook. Patch is included as well.
case 'view':
case 'load':
$node->flags = flag_get_counts("node", $node->nid);
break;
| Comment | File | Size | Author |
|---|---|---|---|
| flag.module.diff | 375 bytes | pianomansam |
Comments
Comment #1
quicksketchYes this is possible, but probably unnecessary. Why should we unconditionally cause extra data to be loaded into every node when it only takes a single function call to get that data?
Comment #2
mooffie commented(This is a duplicate of #302062: Expose user-defined flags to modules/themes via $node)
Comment #3
quicksketchIt's very similar, but it's not quite a duplicate since #302062 just puts Flag objects into the $node object. This issue should probably be setting $node->flag_counts and not $node->flags, since it's not really the applicable flags that are being added to the $node. This patch also has a greater performance hit than the other issue, since the flag counts are NOT always loaded.
Comment #4
pianomansam commentedGood points. For me, it made sense to put the flags inside the node object to keep the logic (controller) separate from the display (view). Do what you will with it, but I do think there should be some easy way to grab the flags for a node without having to use PHP.
Comment #5
mooffie commentedYou have some misunderstanding of the MVC paradigm:
===
What you're looking for is to make your views cleaner. That's a very good thing. So you can move your code to a node template preprocess function. This way it won't affect performance. (Another possibility: suggest us some useful query method(s) to add to the Flag handler class.)
When you load things unconditionally onto $node that's the opposite of lazy programming and that's something we should avoid. If we weren't hindered by the PHP language (or by current Drupal programming conventions) we could add a lazy method/property to $node, but we can't. So what we provide is the $flag handler. Perhaps, as Drpual evolves, things would change.
Comment #6
mooffie commentedExamples for this technique you'll find in the handbook. For example, in the "How to add CSS classes to nodes, based on flags set" page.
Comment #7
mitchell commentedI personally do stuff like this using with views block. See the documentation page on How to setup a "Who's bookmarked this" tab. It's uses the same principle of setting the default argument based on the page you're looking at.
Comment #8
quicksketchI'd like to keep this issue open as something to consider. When answering #474410: Display image on node teaser/body if certain flag is checked, I thought it would be very helpful for *global* flags to be available when doing theming.
Comment #9
quicksketchWell after thinking about it further, I think our current approach is just fine. Loading things into $node is convenient but not particularly necessary. Let's stick with being efficient and not add this option.