protected function FileBase::getFileFieldData in Media Migration 8
Get the name of the file fields from the source database.
Parameters
\Drupal\Core\Database\Connection $connection: The database connection of the source Drupal 7 instance.
bool $field_names_only: Whether only the name of the file fields should be returned. Defaults to TRUE.
Return value
array The array of the available file fields.
1 call to FileBase::getFileFieldData()
- FileBase::getFileData in src/
Plugin/ media_migration/ file_entity/ FileBase.php - Returns display and description properties of the specified file.
File
- src/
Plugin/ media_migration/ file_entity/ FileBase.php, line 53
Class
- FileBase
- Abstract plugin class for file-based media migration source plugins.
Namespace
Drupal\media_migration\Plugin\media_migration\file_entityCode
protected function getFileFieldData(Connection $connection, bool $field_names_only = TRUE) : array {
$field_query = $connection
->select('field_config', 'fs')
->fields('fs', [
'field_name',
])
->condition('fs.type', 'file')
->condition('fs.active', 1)
->condition('fs.deleted', 0)
->condition('fs.storage_active', 1)
->condition('fi.deleted', 0);
$field_query
->join('field_config_instance', 'fi', 'fs.id = fi.field_id');
if ($field_names_only) {
return array_keys($field_query
->execute()
->fetchAllAssoc('field_name'));
}
$field_query
->addField('fs', 'data', 'field_storage_data');
$field_query
->addField('fi', 'data', 'field_instance_data');
$fields_data = [];
foreach ($field_query
->execute()
->fetchAll(\PDO::FETCH_ASSOC) as $item) {
foreach ([
'field_storage_data',
'field_instance_data',
] as $data_key) {
$item[$data_key] = unserialize($item[$data_key]);
}
$fields_data[] = $item;
}
return $fields_data;
}