protected function CiviEntityStorage::prepareLoadedEntity in CiviCRM Entity 8.3
Prepares a loaded entity.
Parameters
array $civicrm_entity: The entity data.
Return value
\Drupal\civicrm_entity\Entity\CivicrmEntity The prepared entity.
Throws
\Drupal\Core\Entity\Sql\SqlContentEntityStorageException
1 call to CiviEntityStorage::prepareLoadedEntity()
File
- src/
CiviEntityStorage.php, line 219
Class
- CiviEntityStorage
- Defines entity class for external CiviCRM entities.
Namespace
Drupal\civicrm_entityCode
protected function prepareLoadedEntity(array $civicrm_entity) {
$this
->loadFromDedicatedTables($civicrm_entity);
$bundle = FALSE;
if ($this->bundleKey) {
$bundle_property = $this->entityType
->get('civicrm_bundle_property');
if (!isset($civicrm_entity[$bundle_property])) {
throw new EntityStorageException('Missing bundle for entity type ' . $this->entityTypeId);
}
$bundle_value = $civicrm_entity[$bundle_property];
$options = $this->civicrmApi
->getOptions($this->entityType
->get('civicrm_entity'), $bundle_property);
$bundle = $options[$bundle_value];
$transliteration = \Drupal::transliteration();
$bundle = SupportedEntities::optionToMachineName($bundle, $transliteration);
}
$entity = new $this->entityClass([], $this->entityTypeId, $bundle);
// Use initFieldValues to fix CiviCRM data array to Drupal.
$this
->initFieldValues($entity, $civicrm_entity);
return $entity;
}