file_field_find_file_reference_column

file_field_find_file_reference_column(FieldDefinitionInterface $field)

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.

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;
}
doc_Drupal
2016-10-29 09:14:10
Comments
Leave a Comment

Please login to continue.