You are here

class flag_node in Flag 7.3

Same name and namespace in other branches
  1. 5 flag.inc \flag_node
  2. 6.2 flag.inc \flag_node
  3. 6 flag.inc \flag_node
  4. 7.2 flag.inc \flag_node

Implements a node flag.

Hierarchy

Expanded class hierarchy of flag_node

2 string references to 'flag_node'
flag_flag_type_info in ./flag.flag.inc
Implements hook_flag_type_info().
hook_flag_type_info in ./flag.api.php
Define one or more flag types.

File

includes/flag/flag_node.inc, line 11
Contains the flag_node class.

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

    // Use own display settings in the meanwhile.
    $options += array(
      'i18n' => 0,
    );
    return $options;
  }

  /**
   * Options form extras for node 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'),
        'own' => t('Users may only flag content they own'),
        'others' => t('Users may only flag content of 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."),
    );

    // Support for i18n flagging requires Translation helpers module.
    $form['i18n'] = array(
      '#type' => 'radios',
      '#title' => t('Internationalization'),
      '#options' => array(
        '1' => t('Flag translations of content as a group'),
        '0' => t('Flag each translation of content separately'),
      ),
      '#default_value' => $this->i18n,
      '#description' => t('Flagging translations as a group effectively allows users to flag the original piece of content regardless of the translation they are viewing. Changing this setting will <strong>not</strong> update content that has been flagged already.'),
      '#access' => module_exists('translation_helpers'),
      '#weight' => 5,
    );

    // Override the UI texts for nodes.
    $form['display']['show_on_form'] = array(
      '#title' => t('Display checkbox on node edit form'),
      '#description' => t('If you elect to have a checkbox on the node edit form, you may specify its initial state in the settings form <a href="@content-types-url">for each content type</a>.', array(
        '@content-types-url' => url('admin/structure/types'),
      )),
    ) + $form['display']['show_on_form'];

    // Add the 'teaser' view mode as a default value for the entity link display
    // option if this is a new flag.
    if (empty($this->fid)) {
      $form['display']['show_in_links']['#default_value']['teaser'] = 'teaser';
    }
  }
  function type_access_multiple($entity_ids, $account) {
    $access = array();

    // If all subtypes are allowed, we have nothing to say here.
    if (empty($this->types)) {
      return $access;
    }

    // Ensure that only flaggable node types are granted access. This avoids a
    // node_load() on every type, usually done by applies_to_entity_id().
    $result = db_select('node', 'n')
      ->fields('n', array(
      'nid',
    ))
      ->condition('nid', array_keys($entity_ids), 'IN')
      ->condition('type', $this->types, 'NOT IN')
      ->execute();
    foreach ($result as $row) {
      $access[$row->nid] = FALSE;
    }
    return $access;
  }

  /**
   * Adjust the Content ID to find the translation parent if i18n-enabled.
   *
   * @param int $entity_id
   *   The nid for the content.
   *
   * @return int
   *   The tnid if available, the nid otherwise.
   */
  function get_translation_id($entity_id) {
    if ($this->i18n) {
      $node = $this
        ->fetch_entity($entity_id);
      if (!empty($node->tnid)) {
        $entity_id = $node->tnid;
      }
    }
    return $entity_id;
  }
  function flag($action, $entity_id, $account = NULL, $skip_permission_check = FALSE, $flagging = NULL) {
    $entity_id = $this
      ->get_translation_id($entity_id);
    return parent::flag($action, $entity_id, $account, $skip_permission_check, $flagging);
  }

  // Instead of overriding is_flagged() we override get_flagging_record(),
  // which is the underlying method.
  function get_flagging_record($entity_id, $uid = NULL, $sid = NULL) {
    $entity_id = $this
      ->get_translation_id($entity_id);
    return parent::get_flagging_record($entity_id, $uid, $sid);
  }

  /**
   * This is overridden for no other purpose than to document that $entity_id
   * can be one of the following fake IDs in certain contexts:
   *  - 'new': On a new node form.
   *  - 'fake': On the node type admin form.
   */
  function replace_tokens($label, $contexts, $options, $entity_id) {
    return parent::replace_tokens($label, $contexts, $options, $entity_id);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
flag_entity::applies_to_entity function Checks whether the flag applies for the current entity bundle. Overrides flag_flag::applies_to_entity
flag_entity::get_entity_id function Returns the entity id, if it already exists. Overrides flag_flag::get_entity_id 1
flag_entity::get_flag_action function Returns a 'flag action' object. Overrides flag_flag::get_flag_action 2
flag_entity::get_labels_token_types function Returns token types for the current entity type. Overrides flag_flag::get_labels_token_types 1
flag_entity::get_permissions function Provides permissions for this flag. Overrides flag_flag::get_permissions
flag_entity::get_relevant_action_objects function Returns objects the action may possible need. Overrides flag_flag::get_relevant_action_objects 2
flag_entity::get_views_info function Returns information for the Views integration. Overrides flag_flag::get_views_info 1
flag_entity::invoke_rules_event protected function Invoke a Rules event in reaction to a flagging or unflagging. Overrides flag_flag::invoke_rules_event
flag_entity::shows_in_entity_links function Determine whether the flag should show a flag link in entity links. Overrides flag_flag::shows_in_entity_links
flag_entity::_load_entity function Loads the entity object. Overrides flag_flag::_load_entity
flag_flag::$entity_type property The entity type this flag works with.
flag_flag::$errors public property An associative array containing textual errors that may be created during validation.
flag_flag::$fid property The database ID.
flag_flag::$global property Whether this flag state should act as a single toggle to all users.
flag_flag::$name property The flag's "machine readable" name.
flag_flag::$roles property The roles array. This can be populated by fetch_roles() when needed.
flag_flag::$title property The human-readable title for this flag.
flag_flag::$types property The sub-types, AKA bundles, this flag applies to.
flag_flag::access function Determines whether the user may flag, or unflag, the given entity.
flag_flag::access_entity_enabled function Utility function: Checks whether a flag applies to a certain type, and possibly subtype, of entity.
flag_flag::access_multiple function Determine access to multiple objects.
flag_flag::admin_path function Returns administrative menu path for carrying out some action.
flag_flag::applies_to_entity_id function Returns TRUE if the flag applies to the entity with the given ID.
flag_flag::construct function Default constructor. Loads the default options.
flag_flag::delete function Deletes a flag from the database.
flag_flag::disable function Disable a flag provided by a module.
flag_flag::enable function Enable a flag provided by a module.
flag_flag::factory_by_array static function Create a complete flag (except an FID) from an array definition.
flag_flag::factory_by_entity_type static function Another factory method. Returns a new, "empty" flag; e.g., one suitable for the "Add new flag" page.
flag_flag::factory_by_row static function Creates a flag from a database row. Returns it.
flag_flag::fetch_entity function Fetches, possibly from some cache, an entity this flag works with.
flag_flag::fetch_roles function Load this flag's role data from permissions.
flag_flag::find_default_flag function Finds the "default flag" corresponding to this flag.
flag_flag::flagging_delete private function Unflag an entity by deleting a Flagging.
flag_flag::flagging_insert private function Create a new Flagging to flag an entity.
flag_flag::flagging_update private function Update a Flagging.
flag_flag::form_input function Update the flag with settings entered in a form. 1
flag_flag::get_count function Returns the number of times an item is flagged.
flag_flag::get_errors function Returns an array of errors set during validation.
flag_flag::get_flagging function Similar to is_flagged() excepts it returns the flagging entity.
flag_flag::get_label function Processes a flag label for display. This means language translation and token replacements.
flag_flag::get_link_type function Get the link type for this flag.
flag_flag::get_serialized_options function Options are stored serialized in the database.
flag_flag::get_title function A convenience method for getting the flag title.
flag_flag::get_user_count function Returns the number of items a user has flagged.
flag_flag::get_valid_actions function Returns an array of all actions that are executable with this flag.
flag_flag::insert function Saves a new flag to the database. Better use save().
flag_flag::is_compatible function Returns TRUE if this flag's declared API version is compatible with this module.
flag_flag::is_flagged function Determines if a certain user has flagged this object.
flag_flag::new_flagging function Construct a new, empty flagging entity object.
flag_flag::remember_entity function Store an object in the flag handler's cache.
flag_flag::revert function Reverts an overriding flag to its default state.
flag_flag::save function Saves a flag to the database. It is a wrapper around update() and insert().
flag_flag::theme function Renders a flag/unflag link.
flag_flag::theme_suggestions function Provides an array of possible themes to try for a given flag.
flag_flag::type_access function Implements access() implemented by each child class. 1
flag_flag::update function Saves an existing flag to the database. Better use save().
flag_flag::user_access function Determines whether the user has the permission to use this flag.
flag_flag::uses_anonymous_cookies function Returns TRUE if this flag requires anonymous user cookies.
flag_flag::validate function Validates this flag's options.
flag_flag::validate_access function Validates that the current flag's access settings are valid.
flag_flag::validate_name function Validates that the current flag's name is valid.
flag_flag::_decrease_count function Decreases the flag count for an object and clears the static counts cache.
flag_flag::_flag_anonymous function Set a cookie for anonymous users to record their flagging.
flag_flag::_flag_url function A shortcut function to output the link URL.
flag_flag::_increase_count function Increases the flag count for an object and clears the static counts cache.
flag_flag::_is_flagged function Determines if a certain user has flagged this object.
flag_flag::_unflag_anonymous function Remove the cookie for anonymous users to record their unflagging.
flag_node::flag function Flags, or unflags, an item. Overrides flag_flag::flag
flag_node::get_flagging_record function Returns the flagging record. Overrides flag_flag::get_flagging_record
flag_node::get_translation_id function Adjust the Content ID to find the translation parent if i18n-enabled.
flag_node::options function Adds additional options that are common for all entity types. Overrides flag_entity::options
flag_node::options_form function Options form extras for node flags. Overrides flag_entity::options_form
flag_node::replace_tokens function This is overridden for no other purpose than to document that $entity_id can be one of the following fake IDs in certain contexts: Overrides flag_entity::replace_tokens
flag_node::type_access_multiple function Implements access_multiple() implemented by each child class. Overrides flag_flag::type_access_multiple