Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Function used: install_flag_add_flag()
This function accepts an array of options, some of which may need an explanation. Here is a list of the possible keys, value types and some notes:
- name: machine friendly name of the flag
- title: user friendly name of the flag
- content_type: is it a node, or a user that can be flagged? value 'node', or 'user' respectively.
- flag_long: long text displayed when content is shown and not yet flagged
- unflag_long: long test displayed when content is shown and flagged
- flag_message: message displayed to the user when flagging something
- unflag_message: message displayed to the user when unflagging something
- flag_short: short flag message
- unflag_short: short unflag message
- roles: an array of roles names who can use this flag, e.g.:
array('authenticated user')
for authenticated users only. - types: if this is a node flag, then an array (or a string if its just one) of node types this flag will show on.
Example usage to create a flag that marks product (for ubercart for instance) as "wishlisted" for the user:
$data = array(
'name' => 'wishlist',
'title' => 'Wishlist',
'content_type' => 'node',
'roles' => array('authenticated user'),
'types' => 'product'
'flag_long' => 'Add to wishlist',
'unflag_long' => 'Remove from wishlist',
'flag_message' => 'Product added to your Wishlist',
'unflag_message' => 'Product removed from your Wishlist',
'flag_short' => 'Add to wishlist',
'unflag_short' => 'delete',
);
install_flag_add_flag($data);