public static function SourceDatabase::getFormatsHavingFileLink in Media Migration 8
Returns text formats which are formatting text with <a> pointing to a file.
Parameters
\Drupal\Core\Database\Connection $connection: The database connection to the Drupal 7 source database.
string[]|string|null $field_names: The fields to check for the given tag.
string|null $source_entity_type_id: The source entity type ID to filter for.
string|null $source_bundle: The source bundle to filter for.
Return value
string[] Array of text format IDs.
2 calls to SourceDatabase::getFormatsHavingFileLink()
- MediaWysiwygPluginBase::appendProcessor in src/
MediaWysiwygPluginBase.php - Appends the media wysiwyg migrate processor to a field.
- media_migration_migrate_d7_filter_format_prepare_row in ./
media_migration.module - Implements hook_migrate_MIGRATION_ID_prepare_row() for d7_filter_format.
File
- src/
Utility/ SourceDatabase.php, line 77
Class
- SourceDatabase
- Utility class for source database specific routines.
Namespace
Drupal\media_migration\UtilityCode
public static function getFormatsHavingFileLink(Connection $connection, $field_names = NULL, ?string $source_entity_type_id = NULL, ?string $source_bundle = NULL) : array {
if (!\Drupal::moduleHandler()
->moduleExists('linkit')) {
return [];
}
$field_names = $field_names ?? self::getTextFields($connection, $source_entity_type_id, $source_bundle);
if (empty($field_names)) {
return [];
}
// Create a (very big) union query.
$query = NULL;
foreach ((array) $field_names as $field_name) {
$revision_table_exists = $connection
->schema()
->tableExists("field_revision_{$field_name}");
$table = $revision_table_exists ? "field_revision_{$field_name}" : "field_data_{$field_name}";
if (!$revision_table_exists && $connection
->schema()
->tableExists($table)) {
continue;
}
$union_query = $connection
->select($table, $field_name)
->condition("{$field_name}.{$field_name}_value", MediaMigration::SQL_PATTERN_LINKIT_FILE_LINK, 'LIKE')
->groupBy("{$field_name}.{$field_name}_format");
$union_query
->addField($field_name, "{$field_name}_format", 'format');
if ($source_entity_type_id) {
$union_query
->condition("{$field_name}.entity_type", $source_entity_type_id);
if ($source_bundle) {
$union_query
->condition("{$field_name}.bundle", $source_bundle);
}
}
if ($query instanceof SelectInterface) {
$query
->union($union_query);
}
else {
$query = $union_query;
}
}
try {
// The query might return even 'NULL' format.
return array_filter($query
->execute()
->fetchCol());
} catch (DatabaseExceptionWrapper $e) {
}
return [];
}