I'd like to see flags treated like fields for more flexible backend form design and frontend theming. Allow me to demonstrate what I mean with two examples:

Backend Design:
Suppose I don't want my flags all together in a vertical tab labeled "Flags". Suppose I want to intersperse them throughout the node form, or suppose I want to sort them differently per content type, or suppose the label "Flags" doesn't make sense in my application. As it stands, I'd have to write custom code to change any of those things. The same used to be true of taxonomy, and some ugly solutions grew up around the fact. Now that taxonomy terms are fields I can accomplish all those things through configuration in a few minutes, and it's all features exportable.
Frontend Theming:
At present, my options for displaying a flag on a node display are to tack it onto the list of links... or not. There's a function for placing a flag link on a page, but that has to be hard-coded into a template file. Neither option gives a non-developer the flexibility to position a flag on the page through the administrative interface as you can do with fields.* If flags were implemented more like fields, I could position them from the backend without programming skill and make changes without touching the file system, put them inside field groups, and have a field-level template to theme.

*The best solution I can find for this for Drupal 7 is (in theory) to use flag_create_link() in a Dynamic Field, but that module's not available for D7 yet. Computed Field actually does the same thing and has a functioning D7 dev version.

I'm sure that what I'm proposing represents a large effort, but I think it would be in line with the direction Drupal is taking and would greatly improve the flexibility of the module and potential sophistication of solutions created with it.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

This is all possible through hook_field_extra_fields(), which would allows us to individually place both the flag checkboxes (on the node form) and the flag links (on the node display). We fixed up our implementation a bit in this issue: #1136248: Update hook_field_extra_fields() for ordering Flag fieldset on forms, though the treatment is still pretty much the same as the D6 version.

I'd probably prefer to avoid the Taxonomy approach of requiring users to set up a widget on the node form. In the case of Flag, there's little need for anything more than a checkbox, so having multiple widgets on the node form seems unlikely (but not impossible, users might want to add description text or use radio buttons for example). As flexible as the Taxonomy approach may be, I find the whole process incredibly confusing and difficult. Utilizing hook_field_extra_fields() may provide a compromise where individual flag checkboxes and links may be moved around, though I imagine that there will always be (a few) users who will want different Flag widgets on the node form.

TravisCarden’s picture

Issue summary: View changes

Updated issue summary.

TravisCarden’s picture

Issue summary: View changes

Updated issue summary.

TravisCarden’s picture

Issue summary: View changes

Updated issue summary.

TravisCarden’s picture

Issue summary: View changes

Updated issue summary.

aa2007’s picture

I have tried to display the flag with the computed field but I did not work..
I filled out the field Computed Code (PHP):

$entity_field[0]['value'] = flag_create_link('product_comparison', $node->nid);

And Display Code (PHP):

$display_output = $entity_field_item['value'];

But at the node I get the error:

Notice: Undefined variable: node at function eval() (line 1 at file /home/111/sites/all/modules/computed_field/computed_field.module(439) : eval()'d code).
Notice: Trying to get property of non-object at function eval() (line 1 at file /home/111/sites/all/modules/computed_field/computed_field.module(439) : eval()'d code).
Notice: Undefined variable: node at function eval() (line 1 at file/home/111/sites/all/modules/computed_field/computed_field.module(439) : eval()'d code).
Notice: Trying to get property of non-object at function eval() (line 1 at file/home/111/sites/all/modules/computed_field/computed_field.module(439) : eval()'d code).
Notice: Undefined variable: node at function eval() (line 1 at file/home/111/sites/all/modules/computed_field/computed_field.module(439) : eval()'d code).
Notice: Trying to get property of non-object at function eval() (line 1 at file/home/111/sites/all/modules/computed_field/computed_field.module(439) : eval()'d code).
Notice: Undefined variable: node at function eval() (line1 at file/home/111/sites/all/modules/computed_field/computed_field.module(439) : eval()'d code).
Notice: Trying to get property of non-object at function eval() (line 1 at file/home/111/sites/all/modules/computed_field/computed_field.module(439) : eval()'d code).

TravisCarden’s picture

@aa2007, you actually don't need (or want) to store a value for the field in the database—it needs to be re-computed every time it's displayed. Instead, leave the Computed Code (PHP) at its default:

$entity_field[0]['value'] = "";

...and move the computation to Display Code (PHP):

$display_output = flag_create_link('product_comparison', $node->nid);

See if that does the trick.

aa2007’s picture

Fewer errors, but the flags will still not work.

* Notice: Undefined variable: node at function eval() (line 1 at file /home/111/sites/all/modules/computed_field/computed_field.module(318) : eval()'d code).
* Notice: Trying to get property of non-object at function eval() (line 1 at file /home/111/sites/all/modules/computed_field/computed_field.module(318) : eval()'d code).

aa2007’s picture

Title: Treat flags like fields for more flexible backend and frontend design » Notice: Undefined index: filter

oops

aa2007’s picture

Title: Notice: Undefined index: filter » Treat flags like fields for more flexible backend and frontend design

changed title back

TravisCarden’s picture

@aa007, would you be so kind as to open a separate issue (as a support request) so we can keep this one focused on the feature request? Thanks.

TravisCarden’s picture

Issue summary: View changes

Updated issue summary.

heronog’s picture

have you guys seen this? http://drupal.org/node/1249744

heronog’s picture

Try with

$display_output = flag_create_link('product_comparison', $entity->nid);

in D7 Computed Field the $entity contains the $node (when you are adding the field to a node)

aa2007’s picture

heronog, thx!
I've looked at examples of the Computed Field and now I know how to get the nid. That's what I wrote to a different theme: http://drupal.org/node/1387410 # comment-5432806
But in any case, thanks again!

joachim’s picture

Title: Treat flags like fields for more flexible backend and frontend design » [meta] Treat flags like fields for more flexible backend and frontend design
Version: 7.x-2.x-dev » 7.x-3.x-dev

Keeping this open as a general discussion. Though I broadly agree with the previous maintainer in comment #1.

If you want to separate out hook_field_extra_fields() I could go for that. Maybe as an extra option per flag to break out of the main flag extra field? This should be covered in a spin-off issue though.

Devin Carlson’s picture

Version: 7.x-3.x-dev » 7.x-2.x-dev
Status: Active » Needs review
FileSize
1 KB

A patch to implement flag_field_extra_fields() for flag display. This allows flags to be easily positioned in relation to other fields.

Moving to 7.x-2.x for testing; will forward-port to 3.x shortly.

Status: Needs review » Needs work

The last submitted patch, treat-flags-like-fields-1376568-12.patch, failed testing.

joachim’s picture

Thanks for that patch!

This specific functionality is covered by #1892930: Placement of flag links as pseudofields though. Sorry, I should have done some issue queue maintenance and linked to that from here, which is a meta-issue.

TravisCarden’s picture

@joachim, what relationship did you intend between this issue and #1376568: [meta] Treat flags like fields for more flexible backend and frontend design? There may be some detail there that would aid in this discussion. And from the other direction, if the work to satisfy it is actually going to be done here, a link in that one's issue summary would probably be helpful.

joachim’s picture

Well this one is intended to be the meta-issue, that is, for general discussion about a fairly wide-reaching topic which includes changes to both the back-end and UI.

The other one is for the specific change to output flag links as pseudofields.

If you can help with the blocking issue, then that one should be a fairly easy one to get in!

TravisCarden’s picture

Oops! I meant to post that comment on the other issue. Glad you understood what I was trying to do anyway, @joachim. :-P Thanks for the clarification.

joachim’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
Status: Needs work » Active
joachim’s picture

Issue summary: View changes

Updated issue summary.

joachim’s picture

Status: Active » Closed (won't fix)

Closing this.

Flag links as pseudofield got in ages ago; anything else is wontfix.