public function StateInformation::createImportStatusOfEntity in Entity Share 8.3
Creates a dedicated "Entity import status" entity for imported entity.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity being imported.
array $parameters: Other data from the import context, with valid keys:
- remote_website.
- channel_id.
- policy.
Return value
\Drupal\entity_share_client\Entity\EntityImportStatusInterface|bool The newly created "Entity import status" entity or FALSE on failure.
Overrides StateInformationInterface::createImportStatusOfEntity
File
- modules/
entity_share_client/ src/ Service/ StateInformation.php, line 242
Class
- StateInformation
- Service to handle presentation of import state.
Namespace
Drupal\entity_share_client\ServiceCode
public function createImportStatusOfEntity(ContentEntityInterface $entity, array $parameters) {
try {
$entity_storage = $this->entityTypeManager
->getStorage('entity_import_status');
$entity_import_status_data = [
'entity_id' => $entity
->id(),
'entity_uuid' => $entity
->uuid(),
'entity_type_id' => $entity
->getEntityTypeId(),
'entity_bundle' => $entity
->bundle(),
'last_import' => $this->time
->getRequestTime(),
];
if ($entity_storage
->getEntityType()
->hasKey('langcode')) {
$entity_import_status_data['langcode'] = $entity
->language()
->getId();
}
foreach ([
'remote_website',
'channel_id',
'policy',
] as $additional_parameter) {
if (!empty($parameters[$additional_parameter])) {
$entity_import_status_data[$additional_parameter] = $parameters[$additional_parameter];
}
}
$import_status_entity = $entity_storage
->create($entity_import_status_data);
$import_status_entity
->save();
return $import_status_entity;
} catch (\Exception $e) {
// @todo log the error.
return FALSE;
}
}