public function FileDealerManager::createInstanceFromSchemeAndMime in Media Migration 8
Returns a FileDealer plugin instance that matches the scheme and MIME.
FileDealer plugins may specify scheme ("public", "private" etc) and MIMEs ("image", "audio" etc). This method returns a plugin that is able to manage the migration of files with the given storage scheme and main MIME type:
- For first, the manager tries to find a plugin that exactly matches the given scheme and MIME.
- When no plugin was found that strictly matches, then the manager tries find a plugin that's scheme isn't limited, but the given MIME matches.
- When no plugin was found that matches to the given MIME, then this method tries to return a plugin instance whose MIME isn't limited, but its specified scheme matches the scheme argument.
- When no matching plugin was found, but the default "fallback" plugin is available, then a fallback plugin instance will be returned.
Parameters
string $scheme: The URI scheme.
string $mime: The main MIME type's first part.
Return value
\Drupal\media_migration\FileDealerPluginInterface|null A fully configured plugin instance or NULL if no applicable plugin was found.
Overrides FileDealerManagerInterface::createInstanceFromSchemeAndMime
File
- src/
FileDealerManager.php, line 95
Class
- FileDealerManager
- Manages discovery and instantiation of plain file dealer plugins.
Namespace
Drupal\media_migrationCode
public function createInstanceFromSchemeAndMime(string $scheme, string $mime) {
$filtered_definitions = $this
->getDefinitionsByFieldTypeAndScheme($scheme, $mime);
if (!empty($filtered_definitions)) {
try {
$configuration = [
'scheme' => $scheme,
'mime' => $mime,
];
$plugin_id = array_keys($filtered_definitions)[0];
return $this
->createInstance($plugin_id, $configuration);
} catch (PluginException $e) {
return NULL;
}
}
return NULL;
}