updated flag module to 7.x-3.6 (2015-mar-02)

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-20 20:01:42 +02:00
parent 785dee0639
commit eeb0df349d
41 changed files with 2024 additions and 521 deletions
+200 -98
View File
@@ -33,6 +33,7 @@ function flag_entity_info() {
// The following tells EntityAPI how to save flaggings, thus allowing use
// of Entity metadata wrappers (if present).
'save callback' => 'flagging_save',
'creation callback' => 'flagging_create',
),
);
@@ -72,6 +73,37 @@ function flagging_load($flagging_id, $reset = FALSE) {
return reset($result);
}
/**
* Entity API creation callback.
*
* Creates an unsaved flagging object for use with $flag->flag().
*
* @param $values
* An array of values as described by the entity's property info. Only
* 'flag_name' or 'fid' must be specified, since $flag->flag() does the rest.
*
* @return
* An unsaved flagging object containing the property values.
*/
function flagging_create($values = array()) {
$flagging = (object) array();
if (!isset($values['flag_name'])) {
if (isset($values['fid'])) {
// Add flag_name, determined from fid.
$flag = flag_get_flag(NULL, $values['fid']);
$values['flag_name'] = $flag->name;
}
}
// Apply the given values.
foreach ($values as $key => $value) {
$flagging->$key = $value;
}
return $flagging;
}
/**
* Saves a flagging entity.
*
@@ -128,14 +160,15 @@ function flagging_save($flagging) {
// @todo: flag_reset_flag():
// - it should delete the flaggings.
// - (it has other issues; see http://drupal.org/node/894992.)
// - (is problematic: it might not be possible to delete all data in a single page request.)
// - (is problematic: it might not be possible to delete all data in a single
// page request.)
// @todo: Discuss: Note that almost all functions/identifiers dealing with
// flaggings *aren't* prefixed by "flag_". For example:
// - The menu argument is %flagging, not %flag_flagging.
// - The entity type is "flagging", not "flag_flagging".
// On the one hand this succinct version is readable and nice. On the other hand, it isn't
// very "correct".
// - The menu argument is %flagging, not %flag_flagging.
// - The entity type is "flagging", not "flag_flagging".
// On the one hand this succinct version is readable and nice. On the other
// hand, it isn't very "correct".
/**
* Implements hook_entity_query_alter().
@@ -150,7 +183,8 @@ function flag_entity_query_alter(EntityFieldQuery $query) {
// Alter only flagging queries with bundle conditions.
if (isset($conditions['entity_type']) && $conditions['entity_type']['value'] == 'flagging' && isset($conditions['bundle'])) {
$query->addTag('flagging_flag_names'); // Add tag to alter query.
// Add tag to alter query.
$query->addTag('flagging_flag_names');
// Make value and operator of the bundle condition accessible
// in hook_query_TAG_alter.
$query->addMetaData('flag_name_value', $conditions['bundle']['value']);
@@ -185,7 +219,6 @@ function flag_menu() {
'access arguments' => array('administer flags'),
'description' => 'Configure flags for marking content with arbitrary information (such as <em>offensive</em> or <em>bookmarked</em>).',
'file' => 'includes/flag.admin.inc',
'type' => MENU_NORMAL_ITEM,
);
$items[FLAG_ADMIN_PATH . '/list'] = array(
'title' => 'List',
@@ -207,7 +240,7 @@ function flag_menu() {
'page arguments' => array('flag_import_form'),
'access arguments' => array('use flag import'),
'file' => 'includes/flag.export.inc',
'type' => MENU_LOCAL_TASK,
'type' => MENU_LOCAL_ACTION,
'weight' => 2,
);
$items[FLAG_ADMIN_PATH . '/export'] = array(
@@ -216,24 +249,26 @@ function flag_menu() {
'page arguments' => array('flag_export_form'),
'access arguments' => array('administer flags'),
'file' => 'includes/flag.export.inc',
'type' => MENU_LOCAL_TASK,
'type' => MENU_LOCAL_ACTION,
'weight' => 3,
);
$items[FLAG_ADMIN_PATH . '/manage/%flag'] = array(
'load arguments' => array(TRUE), // Allow for disabled flags.
// Allow for disabled flags.
'load arguments' => array(TRUE),
'page callback' => 'drupal_get_form',
'page arguments' => array('flag_form', FLAG_ADMIN_PATH_START + 1),
'access callback' => 'user_access',
'access arguments' => array('administer flags'),
'file' => 'includes/flag.admin.inc',
'type' => MENU_CALLBACK,
'type' => MENU_LOCAL_TASK,
// Make the flag title the default title for descendant menu items.
'title callback' => '_flag_menu_title',
'title arguments' => array(FLAG_ADMIN_PATH_START + 1),
);
$items[FLAG_ADMIN_PATH . '/manage/%flag/edit'] = array(
'load arguments' => array(TRUE), // Allow for disabled flags.
// Allow for disabled flags.
'load arguments' => array(TRUE),
'title' => 'Edit flag',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
@@ -257,7 +292,8 @@ function flag_menu() {
'type' => MENU_CALLBACK,
);
$items[FLAG_ADMIN_PATH . '/manage/%flag/update'] = array(
'load arguments' => array(TRUE), // Allow for disabled flags.
// Allow for disabled flags.
'load arguments' => array(TRUE),
'title' => 'Update',
'page callback' => 'flag_update_page',
'page arguments' => array(FLAG_ADMIN_PATH_START + 1),
@@ -306,31 +342,6 @@ function flag_admin_menu_map() {
),
);
if (module_exists('field_ui')) {
foreach (entity_get_info() as $obj_type => $info) {
if ($obj_type == 'flagging') {
foreach ($info['bundles'] as $bundle_name => $bundle_info) {
if (isset($bundle_info['admin'])) {
$fields = array();
foreach (field_info_instances($obj_type, $bundle_name) as $field) {
$fields[] = $field['field_name'];
}
$arguments = array(
'%flag' => array($bundle_name),
'%field_ui_menu' => $fields,
);
$path = $bundle_info['admin']['path'];
$map["$path/fields/%field_ui_menu"]['parent'] = "$path/fields";
$map["$path/fields/%field_ui_menu"]['arguments'][] = $arguments;
}
}
}
}
}
return $map;
}
@@ -384,9 +395,11 @@ function flag_help($path, $arg) {
case FLAG_ADMIN_PATH:
$output = '<p>' . t('This page lists all the <em>flags</em> that are currently defined on this system.') . '</p>';
return $output;
case FLAG_ADMIN_PATH . '/add':
$output = '<p>' . t('Select the type of flag to create. An individual flag can only affect one type of object. This cannot be changed once the flag is created.') . '</p>';
return $output;
case FLAG_ADMIN_PATH . '/manage/%/fields':
// Get the existing link types that provide a flagging form.
$link_types = flag_get_link_types();
@@ -540,10 +553,10 @@ function flag_get_types() {
function flag_create_handler($entity_type) {
$definition = flag_fetch_definition($entity_type);
if (isset($definition) && class_exists($definition['handler'])) {
$handler = new $definition['handler'];
$handler = new $definition['handler']();
}
else {
$handler = new flag_broken;
$handler = new flag_broken();
}
$handler->entity_type = $entity_type;
$handler->construct();
@@ -566,6 +579,8 @@ function flag_permission() {
),
);
// Reset static cache to ensure all flag permissions are available.
drupal_static_reset('flag_get_flags');
$flags = flag_get_flags();
// Provide flag and unflag permissions for each flag.
foreach ($flags as $flag_name => $flag) {
@@ -616,12 +631,19 @@ function flag_field_extra_fields() {
continue;
}
foreach ($flag->types as $bundle_name) {
$applicable_bundles = $flag->types;
// If the list of bundles is empty, it indicates all bundles apply.
if (empty($applicable_bundles)) {
$entity_info = entity_get_info($flag->entity_type);
$applicable_bundles = array_keys($entity_info['bundles']);
}
foreach ($applicable_bundles as $bundle_name) {
if ($flag->show_on_form) {
$extra[$flag->entity_type][$bundle_name]['form']['flag'] = array(
'label' => t('Flags'),
'description' => t('Checkboxes for toggling flags'),
'weight' => 10
'weight' => 10,
);
}
@@ -689,7 +711,7 @@ function flag_form_node_type_form_alter(&$form, &$form_state, $form_id) {
* Warning: will not work on entity types that are not fieldable, as this relies
* on a field module hook.
*
* @see flag_field_attach_submit().
* @see flag_field_attach_submit()
*/
function flag_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
list($id) = entity_extract_ids($entity_type, $entity);
@@ -698,6 +720,10 @@ function flag_field_attach_form($entity_type, $entity, &$form, &$form_state, $la
$id = NULL;
}
// Keep track of whether the entity is new or not, as we're about to fiddle
// with the entity id for the flag's entity cache.
$is_existing_entity = !empty($id);
// Get all possible flags for this entity type.
$flags = flag_get_flags($entity_type);
@@ -710,7 +736,7 @@ function flag_field_attach_form($entity_type, $entity, &$form, &$form_state, $la
}
// Get the flag status.
if (isset($id)) {
if ($is_existing_entity) {
$flag_status = $flag->is_flagged($id);
}
else {
@@ -719,7 +745,8 @@ function flag_field_attach_form($entity_type, $entity, &$form, &$form_state, $la
$flag_status = FALSE;
// Apply the per-bundle defaults for nodes.
if ($entity_type == 'node') {
$flag_status = variable_get('flag_' . $flag->name . '_default_' . $form['type']['#value'], 0);
$node_type = $entity->type;
$flag_status = variable_get('flag_' . $flag->name . '_default_' . $node_type, 0);
}
// For a new, unsaved entity, make a dummy entity ID so that the flag
@@ -793,7 +820,7 @@ function flag_field_attach_form($entity_type, $entity, &$form, &$form_state, $la
/**
* Implements hook_field_attach_submit().
*
* @see flag_field_attach_form().
* @see flag_field_attach_form()
*/
function flag_field_attach_submit($entity_type, $entity, $form, &$form_state) {
// This is invoked for each flag_field_attach_form(), but possibly more than
@@ -831,7 +858,7 @@ function flag_field_attach_update($entity_type, $entity) {
/**
* Shared saving routine between flag_field_attach_insert/update().
*
* @see flag_field_attach_form().
* @see flag_field_attach_form()
*/
function flag_field_attach_save($entity_type, $entity) {
list($id) = entity_extract_ids($entity_type, $entity);
@@ -872,13 +899,14 @@ function flag_contextual_links_view_alter(&$element, $items) {
list($entity_id) = entity_extract_ids($entity_type, $entity);
if (!$flag->access($entity_id) && (!$flag->is_flagged($entity_id) || !$flag->access($entity_id, 'flag'))) {
// User has no permission to use this flag or flag does not apply to this
// object. The link is not skipped if the user has "flag" access but
// not "unflag" access (this way the unflag denied message is shown).
// User has no permission to use this flag or flag does not apply to
// this object. The link is not skipped if the user has "flag" access
// but not "unflag" access (this way the unflag denied message is
// shown).
continue;
}
$element['#links']['flag-'. $name] = array(
$element['#links']['flag-' . $name] = array(
'title' => $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id),
'html' => TRUE,
);
@@ -935,7 +963,7 @@ function flag_entity_view($entity, $type, $view_mode, $langcode) {
// The pseudofield output.
if ($flag->show_as_field) {
$entity->content['flag_' . $flag->name] = array(
'#markup' => $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id, array('needs_wrapping_element' => TRUE)),
'#markup' => $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id, array('needs_wrapping_element' => TRUE)),
);
}
}
@@ -1136,7 +1164,7 @@ function flag_user_delete($account) {
function flag_user_account_removal($account) {
// Remove flags by this user.
$query = db_select('flagging', 'fc');
$query->leftJoin('flag_counts', 'c', 'fc.entity_id = c.entity_id AND fc.entity_type = c.entity_type');
$query->leftJoin('flag_counts', 'c', 'fc.entity_id = c.entity_id AND fc.entity_type = c.entity_type AND fc.fid = c.fid');
$result = $query
->fields('fc', array('fid', 'entity_id'))
->fields('c', array('count'))
@@ -1313,8 +1341,9 @@ function flag_flag_trigger($action, $flag, $entity_id, $account, $flagging) {
$object = $flag->fetch_entity($entity_id);
// Generic "all flags" actions.
foreach (trigger_get_assigned_actions('flag_' . $action) as $aid => $action_info) {
// The 'if ($aid)' is a safeguard against http://drupal.org/node/271460#comment-886564
foreach (trigger_get_assigned_actions('flag_' . $action) as $aid => $action_info) {
// The 'if ($aid)' is a safeguard against
// http://drupal.org/node/271460#comment-886564
if ($aid) {
actions_do($aid, $object, $context);
}
@@ -1513,8 +1542,8 @@ function template_preprocess_flag(&$variables) {
$flag =& $variables['flag'];
$action = $variables['action'];
$entity_id = $variables['entity_id'];
$errors = join('<br />', $variables['errors']);
$flag_css_name = str_replace('_', '-', $flag->name);
$errors = implode('<br />', $variables['errors']);
$flag_name_css = str_replace('_', '-', $flag->name);
// Generate the link URL.
$link_type = $flag->get_link_type();
@@ -1550,12 +1579,12 @@ function template_preprocess_flag(&$variables) {
$variables['link_text'] = isset($link['title']) ? $link['title'] : $flag->get_label($action . '_short', $entity_id);
$variables['link_title'] = isset($link['attributes']['title']) ? check_plain($link['attributes']['title']) : check_plain(strip_tags($flag->get_label($action . '_long', $entity_id)));
$variables['status'] = ($action == 'flag' ? 'unflagged' : 'flagged');
$variables['flag_name_css'] = $flag_css_name;
$variables['flag_name_css'] = $flag_name_css;
$variables['flag_wrapper_classes_array'] = array();
$variables['flag_wrapper_classes_array'][] = 'flag-wrapper';
$variables['flag_wrapper_classes_array'][] = 'flag-' . $flag_css_name;
$variables['flag_wrapper_classes_array'][] = 'flag-' . $flag_css_name . '-' . $entity_id;
$variables['flag_wrapper_classes_array'][] = 'flag-' . $flag_name_css;
$variables['flag_wrapper_classes_array'][] = 'flag-' . $flag_name_css . '-' . $entity_id;
$variables['flag_classes_array'] = array();
$variables['flag_classes_array'][] = 'flag';
@@ -1583,7 +1612,8 @@ function template_preprocess_flag(&$variables) {
$variables['message_classes_array'][] = 'flag-' . $variables['status'] . '-message';
$variables['message_text'] = $flag->get_label($inverse_action . '_message', $entity_id);
$variables['flag_classes_array'][] = $variables['status'];
// By default we make our JS code remove, after a few seconds, only success messages.
// By default we make our JS code remove, after a few seconds, only
// success messages.
$variables['message_classes_array'][] = 'flag-auto-remove';
}
}
@@ -1646,12 +1676,21 @@ function _flag_link_type_descriptions() {
// Non-Views public API
/**
* Get the count of flags for a certain entity.
* Get the count of flags for a particular entity type.
*
* When called during a flagging or unflagging (such as from a hook
* implementation or from Rules), the flagging or unflagging that is in the
* process of being performed:
* - will be included during a flagging operation
* - will STILL be included during an unflagging operation. That is, the count
* will not yet have been decreased.
* This is because this queries the {flagging} table, which only has its record
* deleted at the very end of the unflagging process.
*
* @param $flag
* The flag.
* @param $entity_type
* The entity type (usually 'node').
* The entity type. For example, 'node'.
*
* @return
* The flag count with the flag name and entity type as the array key.
@@ -1670,7 +1709,7 @@ function flag_get_entity_flag_counts($flag, $entity_type) {
->countQuery()
->execute()
->fetchField();
$counts[$flag->name][$entity_type] = $result;
$counts[$flag->name][$entity_type] = $result;
}
return $counts[$flag->name][$entity_type];
@@ -1679,6 +1718,15 @@ function flag_get_entity_flag_counts($flag, $entity_type) {
/**
* Get the user's flag count.
*
* When called during a flagging or unflagging (such as from a hook
* implementation or from Rules), the flagging or unflagging that is in the
* process of being performed:
* - will be included during a flagging operation
* - will STILL be included during an unflagging operation. That is, the count
* will not yet have been decreased.
* This is because this queries the {flagging} table, which only has its record
* deleted at the very end of the unflagging process.
*
* @param $flag
* The flag.
* @param $user
@@ -1710,13 +1758,17 @@ function flag_get_user_flag_counts($flag, $user) {
/**
* Get flag counts for all flags on a node.
*
* When called during a flagging or unflagging (such as from a hook
* implementation or from Rules), the count this returns takes into account the
* the flagging or unflagging that is in the process of being performed.
*
* @param $entity_type
* The entity type (usually 'node').
* @param $entity_id
* The entity ID (usually the node ID).
*
* @return
* The flag count with the entity type and id as array keys.
* The flag count with the flag names as array keys.
*/
function flag_get_counts($entity_type, $entity_id) {
$counts = &drupal_static(__FUNCTION__);
@@ -1742,6 +1794,10 @@ function flag_get_counts($entity_type, $entity_id) {
/**
* Get the total count of items flagged within a flag.
*
* When called during a flagging or unflagging (such as from a hook
* implementation or from Rules), the count this returns takes into account the
* the flagging or unflagging that is in the process of being performed.
*
* @param $flag_name
* The flag name for which to retrieve a flag count.
* @param $reset
@@ -1756,7 +1812,7 @@ function flag_get_flag_counts($flag_name, $reset = FALSE) {
if (!isset($counts[$flag_name])) {
$flag = flag_get_flag($flag_name);
$counts[$flag_name] = db_select('flag_counts', 'fc')
->fields('fc', array('flagging_id'))
->fields('fc', array('fid'))
->condition('fid', $flag->fid)
->countQuery()
->execute()
@@ -1822,7 +1878,14 @@ function flag_get_flags($entity_type = NULL, $content_subtype = NULL, $account =
$query = db_select('flag', 'f');
$query->leftJoin('flag_types', 'fn', 'fn.fid = f.fid');
$result = $query
->fields('f', array('fid', 'entity_type', 'name', 'title', 'global', 'options'))
->fields('f', array(
'fid',
'entity_type',
'name',
'title',
'global',
'options',
))
->fields('fn', array('type'))
->execute();
foreach ($result as $row) {
@@ -1847,7 +1910,8 @@ function flag_get_flags($entity_type = NULL, $content_subtype = NULL, $account =
// Ensure overridden flags are associated with their parent module.
$flags[$name]->module = $default_flag->module;
// Update the flag with any properties that are "locked" by the code version.
// Update the flag with any properties that are "locked" by the code
// version.
if (isset($default_flag->locked)) {
$flags[$name]->locked = $default_flag->locked;
foreach ($default_flag->locked as $property) {
@@ -1916,32 +1980,39 @@ function flag_get_default_flags($include_disabled = FALSE) {
$default_flags = array();
$flag_status = variable_get('flag_default_flag_status', array());
$default_flags_info = array();
foreach (module_implements('flag_default_flags') as $module) {
$function = $module . '_flag_default_flags';
foreach ($function() as $flag_name => $flag_info) {
// Backward compatibility: old exported default flags have their names
// in $flag_info instead, so we use the += operator to not overwrite it.
$flag_info += array(
// in $flag_info instead, so we use the + operator to not overwrite it.
$default_flags_info[$flag_name] = $flag_info + array(
'name' => $flag_name,
'module' => $module,
);
$flag = flag_flag::factory_by_array($flag_info);
}
}
// Disable flags that are not at the current API version.
if (!$flag->is_compatible()) {
$flag->status = FALSE;
}
// Allow modules to alter definitions using hook_flag_default_flags_alter().
drupal_alter('flag_default_flags', $default_flags_info);
// Add flags that have been enabled.
if ((!isset($flag_status[$flag->name]) && (!isset($flag->status) || $flag->status)) || !empty($flag_status[$flag->name])) {
$flag->status = TRUE;
$default_flags[$flag->name] = $flag;
}
// Add flags that have been disabled.
elseif ($include_disabled) {
$flag->status = FALSE;
$default_flags[$flag->name] = $flag;
}
foreach ($default_flags_info as $flag_info) {
$flag = flag_flag::factory_by_array($flag_info);
// Disable flags that are not at the current API version.
if (!$flag->is_compatible()) {
$flag->status = FALSE;
}
// Add flags that have been enabled.
if ((!isset($flag_status[$flag->name]) && (!isset($flag->status) || $flag->status)) || !empty($flag_status[$flag->name])) {
$flag->status = TRUE;
$default_flags[$flag->name] = $flag;
}
// Add flags that have been disabled.
elseif ($include_disabled) {
$flag->status = FALSE;
$default_flags[$flag->name] = $flag;
}
}
@@ -1958,7 +2029,6 @@ function flag_get_default_flags($include_disabled = FALSE) {
* An array of flagging data, keyed by the flagging ID.
*/
function flag_get_flag_flagging_data($flag_name) {
$return = array();
$flag = flag_get_flag($flag_name);
$result = db_select('flagging', 'fc')
->fields('fc')
@@ -1970,6 +2040,15 @@ function flag_get_flag_flagging_data($flag_name) {
/**
* Find what a user has flagged, either a single entity or on the entire site.
*
* When called during a flagging or unflagging (such as from a hook
* implementation or from Rules), the flagging or unflagging that is in the
* process of being performed:
* - will be included during a flagging operation
* - will STILL be included during an unflagging operation. That is, the count
* will not yet have been decreased.
* This is because this queries the {flagging} table, which only has its record
* deleted at the very end of the unflagging process.
*
* @param $entity_type
* The type of entity that will be retrieved. Usually 'node'.
* @param $entity_id
@@ -1986,11 +2065,15 @@ function flag_get_flag_flagging_data($flag_name) {
* @return
* If returning a single item's flags (that is, when $entity_id isn't NULL),
* an array of the structure
* [flag_name] => (flagging_id => [flagging_id], uid => [uid], entity_id => [entity_id], timestamp => [timestamp], ...)
* [flag_name] => (
* flagging_id => [flagging_id],
* uid => [uid],
* entity_id => [entity_id],
* timestamp => [timestamp],
* ...)
*
* If returning all items' flags, an array of arrays for each flag:
* [flag_name] => [entity_id] => Object from above.
*
*/
function flag_get_user_flags($entity_type, $entity_id = NULL, $uid = NULL, $sid = NULL) {
$flagged_content = &drupal_static(__FUNCTION__);
@@ -2045,6 +2128,15 @@ function flag_get_user_flags($entity_type, $entity_id = NULL, $uid = NULL, $sid
/**
* Return a list of users who have flagged an entity.
*
* When called during a flagging or unflagging (such as from a hook
* implementation or from Rules), the flagging or unflagging that is in the
* process of being performed:
* - will be included during a flagging operation
* - will STILL be included during an unflagging operation. That is, the count
* will not yet have been decreased.
* This is because this queries the {flagging} table, which only has its record
* deleted at the very end of the unflagging process.
*
* @param $entity_type
* The type of entity that will be retrieved. Usually 'node'.
* @param $entity_id
@@ -2053,10 +2145,14 @@ function flag_get_user_flags($entity_type, $entity_id = NULL, $uid = NULL, $sid
* (optional) The name of a flag if wanting a list specific to a single flag.
*
* @return
* If no flag name is given, an array of flagging data, keyed by the user
* ID that flagged the entity. Each flagging array is structured as
* an array of flag information for each flag, keyed by the flag name. If
* a flag name is specified, only the information for that flag is returned.
* A nested array of flagging records (i.e. rows from the {flagging} table,
* rather than complete Flagging entities). The structure depends on the
* presence of the $flag_name parameter:
* - if $flag_name is omitted, the array is keyed first by the user ID of
* the users that flagged the entity, then by flag name. Each value is
* then the flagging record.
* - if $flag_name is given, the array is keyed only by user ID. Each value
* is the flagging record.
* If no flags were found an empty array is returned.
*/
function flag_get_entity_flags($entity_type, $entity_id, $flag_name = NULL) {
@@ -2104,11 +2200,17 @@ function flag_get_entity_flags($entity_type, $entity_id, $flag_name = NULL) {
* The "machine readable" name of the flag; e.g. 'bookmarks'.
* @param $entity_id
* The entity ID to check for flagging, for example a node ID.
* @param $variables
* An array of further variables to pass to theme('flag'). For the full list
* of parameters, see flag.tpl.php. Of particular interest:
* - after_flagging: Set to TRUE if this flag link is being displayed as the
* result of a flagging action.
* - errors: An array of error messages.
*
* @return
* The HTML for the themed flag link.
*/
function flag_create_link($flag_name, $entity_id) {
function flag_create_link($flag_name, $entity_id, $variables = array()) {
$flag = flag_get_flag($flag_name);
if (!$flag) {
// Flag does not exist.
@@ -2118,7 +2220,7 @@ function flag_create_link($flag_name, $entity_id) {
// User has no permission to use this flag.
return;
}
return $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id);
return $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id, $variables);
}
/**
@@ -2150,10 +2252,10 @@ function flag_trim_flag($flag, $account, $cutoff_size, $trim_newest, $permission
$query->orderBy('timestamp', 'ASC');
}
else {
$query->orderBy('timestamp', 'DESC') ;
$query->orderBy('timestamp', 'DESC');
}
// Execute the query
// Execute the query.
$result = $query->execute();
$i = 1;
@@ -2189,7 +2291,7 @@ function flag_reset_flag($flag, $entity_id = NULL) {
}
module_invoke_all('flag_reset', $flag, $entity_id, $rows);
$query = db_delete('flagging')->condition('fid' , $flag->fid);
$query = db_delete('flagging')->condition('fid', $flag->fid);
// Update the flag_counts table.
$count_query = db_delete('flag_counts')->condition('fid', $flag->fid);
if ($entity_id) {
@@ -2508,6 +2610,6 @@ function flag_properties_get_flagging_users($entity, array $options, $name, $ent
* @ingroup callbacks
*/
function flag_properties_get_user_sid($entity, array $options, $name, $entity_type, $property_info) {
$sid = flag_get_sid($entity->uid, FALSE);
$sid = flag_get_sid($entity->uid, FALSE);
return $sid;
}