You are here

public function FlagCount::count in Flag 8.4

Gets the number of flaggings for the given flag and flaggable.

Parameters

\Drupal\flag\FlagInterface $flag: The flag entity.

\Drupal\Core\Entity\EntityInterface $flaggable: The flaggable entity.

Return value

string The number of times the flaggings for the given parameters.

File

src/TwigExtension/FlagCount.php, line 64

Class

FlagCount
Provides a Twig extension to get the flag count given a flag and flaggable.

Namespace

Drupal\flag\TwigExtension

Code

public function count(FlagInterface $flag, EntityInterface $flaggable) {
  $counts = $this->flagCount
    ->getEntityFlagCounts($flaggable);
  return empty($counts) || !isset($counts[$flag
    ->id()]) ? '0' : $counts[$flag
    ->id()];
}