You are here

public function MediaWysiwygPluginManager::createInstanceFromSourceEntityType in Media Migration 8

Returns a media wysiwyg plugin instance for the given source entity type.

Parameters

string $source_entity_type_id: The entity type ID on the source.

Return value

\Drupal\media_migration\MediaWysiwygInterface A media wysiwyg plugin instance for the given source entity type.

Throws

\Drupal\Component\Plugin\Exception\PluginException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

src/MediaWysiwygPluginManager.php, line 60

Class

MediaWysiwygPluginManager
The manager of Media WYSIWYG plugins.

Namespace

Drupal\media_migration

Code

public function createInstanceFromSourceEntityType(string $source_entity_type_id) {
  $definitions = $this
    ->getDefinitions();
  foreach ($definitions as $plugin_id => $plugin_definition) {
    if (in_array($source_entity_type_id, array_keys($plugin_definition['entity_type_map']), TRUE)) {
      return $this
        ->createInstance($plugin_id, [
        'source_entity_type_id' => $source_entity_type_id,
      ]);
    }
  }
  throw new PluginNotFoundException('', sprintf("No MediaWysiwyg plugin was found for source entity type '%s'.", $source_entity_type_id));
}