You are here

private function EntityContext::count in Lightning Core 8.5

Same name and namespace in other branches
  1. 8 tests/contexts/EntityContext.behat.inc \Acquia\LightningExtension\Context\EntityContext::count()
  2. 8.2 tests/contexts/EntityContext.behat.inc \Acquia\LightningExtension\Context\EntityContext::count()
  3. 8.3 tests/contexts/EntityContext.behat.inc \Acquia\LightningExtension\Context\EntityContext::count()
  4. 8.4 tests/contexts/EntityContext.behat.inc \Acquia\LightningExtension\Context\EntityContext::count()

Counts the number of entities of a specific type and optional bundle.

Parameters

string $entity_type: The entity type ID.

string $bundle: (optional) The bundle.

Return value

int How many entities exist of the given type and bundle.

1 call to EntityContext::count()
EntityContext::assertCount in tests/contexts/EntityContext.behat.inc
Asserts that entities of a specific type and optional bundle exist.

File

tests/contexts/EntityContext.behat.inc, line 162

Class

EntityContext
Contains miscellaneous step definitions for working with Drupal entities.

Namespace

Acquia\LightningExtension\Context

Code

private function count($entity_type, $bundle = NULL) {
  $storage = \Drupal::entityTypeManager()
    ->getStorage($entity_type);
  $query = $storage
    ->getQuery()
    ->count();
  if ($bundle) {
    $query
      ->condition($storage
      ->getEntityType()
      ->getKey('bundle'), $bundle);
  }
  return (int) $query
    ->execute();
}