You are here

public function RegistrantsElementUtility::countReferenceableEntities in RNG - Events and Registrations 3.x

Same name and namespace in other branches
  1. 8.2 src/RegistrantsElementUtility.php \Drupal\rng\RegistrantsElementUtility::countReferenceableEntities()
  2. 8 src/RegistrantsElementUtility.php \Drupal\rng\RegistrantsElementUtility::countReferenceableEntities()

Count referenceable identities for an event.

Parameters

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

string $entity_type_id: The identity entity type ID.

array $bundles: (optional) Identity bundles.

Return value

int The count of referencable entities.

1 call to RegistrantsElementUtility::countReferenceableEntities()
RegistrantsElementUtility::peopleTypeOptions in src/RegistrantsElementUtility.php
Generate available people type options suitable for radios element.

File

src/RegistrantsElementUtility.php, line 287

Class

RegistrantsElementUtility

Namespace

Drupal\rng

Code

public function countReferenceableEntities(EntityInterface $event, $entity_type_id, $bundles = []) {

  /** @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManagerInterface $selection_manager */
  $selection_manager = \Drupal::service('plugin.manager.entity_reference_selection');
  $options = [
    'target_type' => $entity_type_id,
    'handler' => 'rng_register',
    'handler_settings' => [
      'event_entity_type' => $event
        ->getEntityTypeId(),
      'event_entity_id' => $event
        ->id(),
    ],
  ];
  if (!empty($bundles)) {
    $options['handler_settings']['target_bundles'] = $bundles;
  }

  /* @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface $selection */
  $selection = $selection_manager
    ->getInstance($options);
  return $selection
    ->countReferenceableEntities();
}