Download & Extend

Add $options parameter to flag_create_link()

Project:Flag
Version:7.x-2.x-dev
Component:Miscellaneous
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

flag_create_link() could benefit from an $options parameter.

What could it be useful for?
1. Changing the link type.
2. Adding to the "suggestions" array.
3. ...

Examples:

<?php
// Disable AJAX:
print flag_create_link('bookmarks', 910, array('link_type' => 'normal'));

// Use the "flag-teaser.tpl.php" template, if exists.
print flag_create_link('bookmarks', 910, array('suggestion' => 'teaser'));
?>

Comments

#1

You could also easily change the link text with this approach. I'm not sure if this would be a good place for passing in template suggestions, though it does seem like it'd be easy enough to implement. Hrmhmm. Maybe this could be useful for advanced uses of Flag in contributed modules.

#2

other options:

allow only flag
allow only unflag

#3

Version:6.x-1.x-dev» 6.x-2.x-dev

Considering this is an API change, it will be handled in the 2.x version.

allow only flag
allow only unflag

This would not be a good idea to handle with flag_create_link(), since it is essentially a theme-level display for actual functionality. Even if the link is not displayed, the content may still be flagged if the API allows it. $flag->access() and hook_flag_access() should be used instead if wanting to deny/allow flagging access.

#4

Please allow adding css class as option, and preferably to the anchor rather than the wrapper.

#5

An options array might also include "what" to be clicked, so when called from a view, even an imagecache preset could be passed in to allow it to be clicked rather than the normal flag-generated field below it.

#6

Version:6.x-2.x-dev» 7.x-2.x-dev

I agree that flag_create_link needs an $options parameter. I was shocked to take a look at the code today and find that I could not even add a simple css class to the link that is being generated.

Because this is a theme-level function that ends up generating a link, it essentially sits on top of drupal's built-in l function. As such, it seems like it would make sense for this function to handle most of the options the the l function handles, namely:

  • 'attributes': An associative array of HTML attributes to apply to the anchor tag. If element 'class' is included, it must be an array; 'title' must be a string; other elements are more flexible, as they just need to work in a call to drupal_attributes($options['attributes']).
  • 'html' (default FALSE): Whether $text is HTML or just plain-text. For example, to make an image tag into a link, this must be set to TRUE, or you will see the escaped HTML image tag. $text is not sanitized if 'html' is TRUE. The calling function must ensure that $text is already safe.
  • 'language': An optional language object. If the path being linked to is internal to the site, $options['language'] is used to determine whether the link is "active", or pointing to the current page (the language as well as the path must match). This element is also used by url().
  • Additional $options elements used by the url() function.

I realize that some of this stuff is not necessarily relevant to a flag link, and some of it is handled via the administrative UI (e.g. the link title)... but surely flag_create_link should allow for something like css styling (and even overriding options set in the UI)?

nobody click here