You are here

public function StateInformation::deleteImportStatusOfEntity in Entity Share 8.3

Deletes the "Entity import status" entity of an entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity which had been imported.

string|null $langcode: Optional language code, used when deleting only specific translations.

Overrides StateInformationInterface::deleteImportStatusOfEntity

File

modules/entity_share_client/src/Service/StateInformation.php, line 307

Class

StateInformation
Service to handle presentation of import state.

Namespace

Drupal\entity_share_client\Service

Code

public function deleteImportStatusOfEntity(EntityInterface $entity, string $langcode = NULL) {

  // If entity is not supported by "entity import", do nothing.
  if (!$entity instanceof ContentEntityInterface) {
    return;
  }
  if (in_array($entity
    ->getEntityTypeId(), [
    'user',
    'entity_import_status',
  ])) {
    return;
  }
  if (!$entity
    ->uuid()) {
    return;
  }
  $entity_storage = $this->entityTypeManager
    ->getStorage('entity_import_status');
  $search_criteria = [
    'entity_id' => $entity
      ->id(),
    'entity_type_id' => $entity
      ->getEntityTypeId(),
  ];
  if ($entity_storage
    ->getEntityType()
    ->hasKey('uuid')) {
    $search_criteria['entity_uuid'] = $entity
      ->uuid();
  }
  if ($langcode && $entity_storage
    ->getEntityType()
    ->hasKey('langcode')) {
    $search_criteria['langcode'] = $langcode;
  }

  /** @var \Drupal\entity_share_client\Entity\EntityImportStatusInterface[] $import_status_entities */
  $import_status_entities = $entity_storage
    ->loadByProperties($search_criteria);
  if ($import_status_entities) {
    foreach ($import_status_entities as $import_status_entity) {
      $import_status_entity
        ->delete();
    }
  }
}