You are here

public function AttributesAwareFieldableEdgeEntityStorageBase::countFieldData in Apigee Edge 8

Determines the number of entities with values for a given field.

Parameters

\Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition: The field for which to count data records.

bool $as_bool: (Optional) Optimizes the query for checking whether there are any records or not. Defaults to FALSE.

Return value

bool|int The number of entities. If $as_bool parameter is TRUE then the value will either be TRUE or FALSE.

Overrides FieldableEdgeEntityStorageBase::countFieldData

See also

\Drupal\Core\Entity\FieldableEntityStorageInterface::purgeFieldData()

File

src/Entity/Storage/AttributesAwareFieldableEdgeEntityStorageBase.php, line 31

Class

AttributesAwareFieldableEdgeEntityStorageBase
Storage for fieldable Edge entities that supports attributes.

Namespace

Drupal\apigee_edge\Entity\Storage

Code

public function countFieldData($storage_definition, $as_bool = FALSE) {

  /** @var \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition */
  $count = 0;

  /** @var \Apigee\Edge\Entity\Property\AttributesPropertyInterface[] $entities */
  $entities = $this
    ->loadMultiple();
  foreach ($entities as $entity) {
    if ($entity
      ->getAttributeValue($storage_definition
      ->getName()) !== NULL) {
      $count++;
    }
  }
  return $as_bool ? (bool) $count : $count;
}