You are here

function file_field_find_file_reference_column in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/file/file.field.inc \file_field_find_file_reference_column()
  2. 10 core/modules/file/file.field.inc \file_field_find_file_reference_column()

Determine whether a field references files stored in {file_managed}.

Parameters

\Drupal\Core\Field\FieldDefinitionInterface $field: A field definition.

Return value

bool The field column if the field references {file_managed}.fid, typically fid, FALSE if it does not.

1 call to file_field_find_file_reference_column()
file_get_file_references in core/modules/file/file.module
Retrieves a list of references to a file.

File

core/modules/file/file.field.inc, line 197
Field module functionality for the File module.

Code

function file_field_find_file_reference_column(FieldDefinitionInterface $field) {
  $schema = $field
    ->getFieldStorageDefinition()
    ->getSchema();
  foreach ($schema['foreign keys'] as $data) {
    if ($data['table'] == 'file_managed') {
      foreach ($data['columns'] as $field_column => $column) {
        if ($column == 'fid') {
          return $field_column;
        }
      }
    }
  }
  return FALSE;
}