function FileReferenceResolver::getReferencingRevision
Returns the most recent revision of a specific entity referencing the file.
Parameters
\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity to do the query for.
\Drupal\file\FileInterface $file: The file entity.
Return value
\Drupal\Core\Entity\FieldableEntityInterface|null A revision referencing that file, if there is any.
1 call to FileReferenceResolver::getReferencingRevision()
- FileReferenceResolver::getReferences in core/
modules/ file/ src/ FileReferenceResolver.php - Retrieves a list of references to a file.
File
-
core/
modules/ file/ src/ FileReferenceResolver.php, line 224
Class
- FileReferenceResolver
- Retrieves file references.
Namespace
Drupal\fileCode
protected function getReferencingRevision(FieldableEntityInterface $entity, FileInterface $file) : ?FieldableEntityInterface {
$storage = $this->entityTypeManager
->getStorage($entity->getEntityTypeId());
assert($storage instanceof RevisionableStorageInterface);
$entity_type = $this->entityTypeManager
->getDefinition($entity->getEntityTypeId());
$query = $storage->getQuery()
->accessCheck(FALSE)
->allRevisions()
->condition($entity_type->getKey('id'), $entity->id());
$fields_condition = $query->orConditionGroup();
foreach ($this->getFileReferenceFields($entity) as $field_name => $field_column) {
$fields_condition->condition($field_name . '.' . $field_column, $file->id());
}
$results = $query->condition($fields_condition)
->sort($entity_type->getKey('revision'), 'DESC')
->range(0, 1)
->execute();
if ($results) {
return $storage->loadRevision(key($results));
}
return NULL;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.