You are here

function civicrm_entity_pseudoconstant_options in CiviCRM Entity 8.3

Implements callback_allowed_values_function().

Provides the pseudoconstant values for CiviCRM entity fields.

Parameters

\Drupal\Core\Field\FieldStorageDefinitionInterface $definition: The field storage definition.

\Drupal\Core\Entity\FieldableEntityInterface|NULL $entity: The entity.

bool $cacheable: If the options are cacheable.

Return value

array The array of field options.

File

./civicrm_entity.module, line 247
Module file for the CiviCRM Entity module.

Code

function civicrm_entity_pseudoconstant_options(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL, &$cacheable = NULL) {

  /** @var \Drupal\civicrm_entity\CiviCrmApiInterface $civicrm_api */
  $civicrm_api = \Drupal::service('civicrm_entity.api');
  $entity_type = \Drupal::entityTypeManager()
    ->getDefinition($definition
    ->getTargetEntityTypeId());
  $options = $civicrm_api
    ->getOptions($entity_type
    ->get('civicrm_entity'), $definition
    ->getName());
  return $options;
}