You are here

function dlike_flag_link in Drupal like (Flag counter) 7.3

Same name and namespace in other branches
  1. 7 dlike.module \dlike_flag_link()
  2. 7.2 dlike.module \dlike_flag_link()

This function is part of flag.module file. This function is overridden here.

1 call to dlike_flag_link()
dlike_entity_view in ./dlike.module
Implements hook_entity_view().

File

./dlike.module, line 109

Code

function dlike_flag_link($type, $object = NULL, $view_mode) {

  // Get all possible flags for this entity type.
  $flags = flag_get_flags($type);
  foreach ($flags as $flag) {

    // Check if the flag outputs on entity view.
    if (!($flag->show_as_field || $flag
      ->shows_in_entity_links($view_mode))) {

      // Flag is not configured to output on entity view, so skip it to save on
      // calls to access checks.
      continue;
    }
    $entity_id = $flag
      ->get_entity_id($object);

    // For a new, unsaved entity, make a dummy entity ID so that the flag
    // handler can remember the entity. This allows access to the flag to be
    // correctly handled in node and comment preview.
    if (is_null($entity_id)) {
      $entity_id = 'new';
    }
    $flag
      ->remember_entity($entity_id, $object);
    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
      // entity. The link is not skipped if the user has "flag" access but
      // not "unflag" access (this way the unflag denied message is shown).
      continue;
    }

    // We're good to go. Output the flag in the appropriate manner(s).
    $dlike_append = dlike_append($type, $entity_id, $flag->name);

    // The old-style entity links output.
    if ($flag
      ->shows_in_entity_links($view_mode)) {

      // The flag links are actually fully rendered theme functions.
      // The HTML attribute is set to TRUE to allow whatever the themer desires.
      $links['flag-' . $flag->name] = array(
        'title' => $flag
          ->theme($flag
          ->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id) . $dlike_append,
        'html' => TRUE,
      );
    }

    // 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' => FALSE,
        )) . $dlike_append,
      );
    }
  }
  if (isset($links)) {
    return $links;
  }
}