function FileReferenceResolver::getFileReferenceFields

Returns file fields for this entity type and bundle.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity to return field information for.

Return value

array<string, string> List of field columns keyed by field name.

2 calls to FileReferenceResolver::getFileReferenceFields()
FileReferenceResolver::getReferences in core/modules/file/src/FileReferenceResolver.php
Retrieves a list of references to a file.
FileReferenceResolver::getReferencingRevision in core/modules/file/src/FileReferenceResolver.php
Returns the most recent revision of a specific entity referencing the file.

File

core/modules/file/src/FileReferenceResolver.php, line 189

Class

FileReferenceResolver
Retrieves file references.

Namespace

Drupal\file

Code

protected function getFileReferenceFields(FieldableEntityInterface $entity) : array {
  $entity_type_id = $entity->getEntityTypeId();
  $bundle = $entity->bundle();
  if (!isset($this->fileFields[$entity_type_id][$bundle])) {
    $this->fileFields[$entity_type_id][$bundle] = [];
    // This contains the possible field names.
    foreach ($entity->getFieldDefinitions() as $field_name => $field_definition) {
      // If this is the first time this field type is seen, check
      // whether it references files.
      if (!isset($this->fieldColumns[$field_definition->getType()])) {
        $this->fieldColumns[$field_definition->getType()] = $this->findFileReferenceColumns($field_definition);
      }
      // If the field type does reference files then record it.
      if ($this->fieldColumns[$field_definition->getType()]) {
        $this->fileFields[$entity_type_id][$bundle][$field_name] = $this->fieldColumns[$field_definition->getType()];
      }
    }
  }
  return $this->fileFields[$entity_type_id][$bundle];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.