You are here

class AuthcacheFlagFlagFragment in Authenticated User Page Caching (Authcache) 7.2

Personalization fragment for retrieving flags.

Hierarchy

Expanded class hierarchy of AuthcacheFlagFlagFragment

See also

flag.module

2 string references to 'AuthcacheFlagFlagFragment'
authcache_flag_authcache_p13n_assembly in modules/authcache_flag/authcache_flag.module
Implements hook_authcache_p13n_assembly().
hook_authcache_p13n_assembly in modules/authcache_p13n/authcache_p13n.api.php
Declare fragment assemblies containing personalized information.

File

modules/authcache_flag/includes/AuthcacheFlagFlagFragment.inc, line 13
Defines a personalization fragment for retrieving flags. on a node.

View source
class AuthcacheFlagFlagFragment implements AuthcacheP13nFragmentInterface, AuthcacheP13nFragmentLoaderInterface, AuthcacheP13nFragmentAccessInterface {
  protected $flagName;

  /**
   * Construct new flag fragment.
   */
  public function __construct($flag_name) {
    $this->flagName = $flag_name;
  }

  /**
   * {@inheritdoc}
   */
  public function load($entity_ids, $context) {
    $flag = flag_get_flag($this->flagName);
    if (!$flag) {
      throw new AuthcacheP13nRequestNotFound();
    }
    return array_fill_keys($entity_ids, $flag);
  }

  /**
   * {@inheritdoc}
   */
  public function check($account, $entity_id, $flag, $context) {
    if (!$flag
      ->access($entity_id) && (!$flag
      ->is_flagged($entity_id) || !$flag
      ->access($entity_id, 'flag'))) {

      // User has no permission to use this flag.
      return FALSE;
    }
    else {
      return TRUE;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function render($entity_id, $flag, $context) {
    return $flag
      ->theme($flag
      ->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AuthcacheFlagFlagFragment::$flagName protected property
AuthcacheFlagFlagFragment::check public function Check whether the user has access to the given fragment. Overrides AuthcacheP13nFragmentAccessInterface::check
AuthcacheFlagFlagFragment::load public function Load the objects designated by the given list of keys. Overrides AuthcacheP13nFragmentLoaderInterface::load
AuthcacheFlagFlagFragment::render public function Render and return fragment. Overrides AuthcacheP13nFragmentInterface::render
AuthcacheFlagFlagFragment::__construct public function Construct new flag fragment.