示例#1
0
  /**
   * {@inheritdoc}
   */
  public function getFlaggings(FlagInterface $flag = NULL, EntityInterface $entity = NULL, AccountInterface $account = NULL) {
    $query = $this->entityQueryManager->get('flagging');

    // The user is supplied with a flag that is not global.
    if (!empty($account) && !empty($flag) && !$flag->isGlobal()) {
      $query->condition('uid', $account->id());
    }

    // The user is supplied but the flag is not.
    if (!empty($account) && empty($flag)) {
       $query->condition('uid', $account->id());
    }
    if (!empty($flag)) {
      $query->condition('flag_id', $flag->id());
    }

    if (!empty($entity)) {
      $query->condition('entity_type', $entity->getEntityTypeId())
                     ->condition('entity_id', $entity->id());
    }

    $ids = $query->execute();

    return $this->getFlaggingsByIds($ids);
  }