You are here

class EntityLikeDislikeVoteCallback in Like & Dislike 7

@file

Hierarchy

Expanded class hierarchy of EntityLikeDislikeVoteCallback

File

src/Controllers/PageControllers/EntityLikeDislikeVoteCallback.php, line 8

Namespace

Drupal\like_and_dislike\Controllers\PageControllers
View source
class EntityLikeDislikeVoteCallback implements \Drupal\cool\Controllers\PageController {

  /**
   * %1 = entity_type
   * %2 = tag
   * %3 = entity_id
   */
  public static function getPath() {
    return 'like_and_dislike/%/%/%';
  }
  public static function accessCallback() {
    return TRUE;
  }
  public static function getDefinition() {
    return array(
      'type' => MENU_CALLBACK,
    );
  }

  /**
   * Handles the when a node or comment is voted with a like.
   * This functions uses a general function to register the vote
   * This function is to be used with AJAX so just prints the counts and message
   */
  public static function pageCallback() {
    $entity_type = arg(1);
    $vote_tag = arg(2);
    $entity_id = arg(3);
    if (isset($entity_type) && isset($vote_tag) && isset($entity_id)) {
      $return = \Drupal\like_and_dislike\Model\Vote::add($entity_id, $entity_type, $vote_tag);
      print $return['likes'] . "/" . $return['dislikes'] . "/" . $return['message'];
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityLikeDislikeVoteCallback::accessCallback public static function
EntityLikeDislikeVoteCallback::getDefinition public static function
EntityLikeDislikeVoteCallback::getPath public static function %1 = entity_type %2 = tag %3 = entity_id
EntityLikeDislikeVoteCallback::pageCallback public static function Handles the when a node or comment is voted with a like. This functions uses a general function to register the vote This function is to be used with AJAX so just prints the counts and message