You are here

public function CiviEntityStorage::getEntityTagEntityId in CiviCRM Entity 8.3

Loads the EntityTag ID.

When saving EntityTag objects, the 'id' that's passed to CiviCRM hooks is not the ID of the EntityTag, but rather the object to which the EntityTag applies. This provides the lookup to determing the ID of the EntityTag object itself.

Parameters

$entityId: The entity ID.

$entityTable: The entity table.

Return value

int|null The EntityTag object's ID, or NULL if not found.

File

src/CiviEntityStorage.php, line 778

Class

CiviEntityStorage
Defines entity class for external CiviCRM entities.

Namespace

Drupal\civicrm_entity

Code

public function getEntityTagEntityId($entityId, $entityTable) {
  $api_params = [
    'sequential' => 1,
    'entity_id' => $entityId,
    'entity_table' => $entityTable,
  ];
  $api_results = civicrm_api3('EntityTag', 'get', $api_params);
  if (!empty($api_results['values'])) {
    foreach ($api_results['values'] as $delta => $result) {
      if ($result['entity_id'] == $entityId) {
        return $result['id'];
      }
    }
  }
}