You are here

class flag_comment in Flag 7.2

Same name and namespace in other branches
  1. 5 flag.inc \flag_comment
  2. 6.2 flag.inc \flag_comment
  3. 6 flag.inc \flag_comment
  4. 7.3 includes/flag/flag_comment.inc \flag_comment

Implements a comment flag.

Hierarchy

Expanded class hierarchy of flag_comment

1 string reference to 'flag_comment'
flag_flag_definitions in ./flag.inc
Implements hook_flag_definitions().

File

./flag.inc, line 1645
Implements various flags. Uses object oriented style inspired by that of Views 2.

View source
class flag_comment extends flag_entity {
  function options() {
    $options = parent::options();

    // Use own display settings in the meanwhile.
    unset($options['show_on_entity']);
    $options += array(
      'access_author' => '',
      'show_on_comment' => TRUE,
    );
    return $options;
  }

  /**
   * Options form extras for comment flags.
   */
  function options_form(&$form) {
    parent::options_form($form);
    $form['access']['access_author'] = array(
      '#type' => 'radios',
      '#title' => t('Flag access by content authorship'),
      '#options' => array(
        '' => t('No additional restrictions'),
        'comment_own' => t('Users may only flag own comments'),
        'comment_others' => t('Users may only flag comments by others'),
        'node_own' => t('Users may only flag comments of nodes they own'),
        'node_others' => t('Users may only flag comments of nodes by others'),
      ),
      '#default_value' => $this->access_author,
      '#description' => t("Restrict access to this flag based on the user's ownership of the content. Users must also have access to the flag through the role settings."),
    );
    $form['display']['show_on_comment'] = array(
      '#type' => 'checkbox',
      '#title' => t('Display link under comment'),
      '#default_value' => $this->show_on_comment,
      '#access' => empty($this->locked['show_on_comment']),
    );
    unset($form['display']['show_on_entity']);
  }
  function type_access_multiple($content_ids, $account) {
    $access = array();

    // Ensure node types are granted access. This avoids a
    // node_load() on every type, usually done by applies_to_content_id().
    $query = db_select('comment', 'c');
    $query
      ->innerJoin('node', 'n', 'c.nid = n.nid');
    $result = $query
      ->fields('c', array(
      'cid',
    ))
      ->condition('c.cid', $content_ids, 'IN')
      ->condition('n.type', $this->types, 'NOT IN')
      ->execute();
    foreach ($result as $row) {
      $access[$row->nid] = FALSE;
    }
    return $access;
  }
  function get_content_id($comment) {

    // Store the comment object in the static cache, to avoid getting it
    // again unneedlessly.
    $this
      ->remember_content($comment->cid, $comment);
    return $comment->cid;
  }
  function uses_hook_link($teaser) {
    return $this->show_on_comment;
  }
  function get_labels_token_types() {
    return array_merge(array(
      'comment',
      'node',
    ), parent::get_labels_token_types());
  }
  function replace_tokens($label, $contexts, $options, $content_id) {
    if ($content_id) {
      if (($comment = $this
        ->fetch_content($content_id)) && ($node = node_load($comment->nid))) {
        $contexts['node'] = $node;
        $contexts['comment'] = $comment;
      }
    }
    return parent::replace_tokens($label, $contexts, $options, $content_id);
  }
  function get_flag_action($content_id) {
    $flag_action = parent::get_flag_action($content_id);
    $comment = $this
      ->fetch_content($content_id);
    $flag_action->content_title = $comment->subject;
    $flag_action->content_url = _flag_url("comment/{$comment->cid}", "comment-{$comment->cid}");
    return $flag_action;
  }
  function get_relevant_action_objects($content_id) {
    $comment = $this
      ->fetch_content($content_id);
    return array(
      'comment' => $comment,
      'node' => node_load($comment->nid),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
flag_comment::get_content_id function Returns the entity id, if it already exists. Overrides flag_entity::get_content_id
flag_comment::get_flag_action function Returns a 'flag action' object. Overrides flag_entity::get_flag_action
flag_comment::get_labels_token_types function Returns token types for the current entity type. Overrides flag_entity::get_labels_token_types
flag_comment::get_relevant_action_objects function Returns objects the action may possible need. Overrides flag_entity::get_relevant_action_objects
flag_comment::options function Adds additional options that are common for all entity types. Overrides flag_entity::options
flag_comment::options_form function Options form extras for comment flags. Overrides flag_entity::options_form
flag_comment::replace_tokens function Replaces tokens. Overrides flag_entity::replace_tokens
flag_comment::type_access_multiple function
flag_comment::uses_hook_link function Returns TRUE if the link should be displayed. Overrides flag_entity::uses_hook_link
flag_entity::applies_to_content_object function Checks whether the flag applies for the current entity bundle.
flag_entity::get_views_info function Returns information for the Views integration. 1
flag_entity::_load_content function Loads the entity object.