public function RecentlyReadService::deleteEntityRecords in Recently Read 8
Delete all "Recently Read" IDs for the entity.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity which might has "Recently Read" records.
\Drupal\Core\Session\AccountInterface|null $user: The user who read the entity.
Overrides RecentlyReadServiceInterface::deleteEntityRecords
File
- src/RecentlyReadService.php, line 174 
Class
- RecentlyReadService
- Recently read service.
Namespace
Drupal\recently_readCode
public function deleteEntityRecords(EntityInterface $entity, AccountInterface $user = NULL) {
  $properties = [
    'type' => $entity
      ->getEntityTypeId(),
    'entity_id' => $entity
      ->id(),
  ];
  if ($user) {
    if ($user
      ->isAnonymous()) {
      $properties['session_id'] = $this->sessionManager
        ->getId();
    }
    else {
      $properties['user_id'] = $user
        ->id();
    }
  }
  $recently_read_entities = $this->recentlyReadStorage
    ->loadByProperties($properties);
  $this->recentlyReadStorage
    ->delete($recently_read_entities);
}