I want to load a plugin definition by its string id within a controller extending ControllerBase. What is the relevant service or class I am looking for?
You can use the plugin manager to fetch a plugin. You only need to find the correct plugin manager service:
$type = \Drupal::service('plugin.manager.service'); // Fill your own plugin manager service. $plugin_definition = $type->getDefinition('plugin_id'); // Fill needed plugin id.
1Ahh yeah, it hit me right after I posted it. I was having trouble locating the plugin manager. I injected it to the controller via
$container->get('plugin.manager.media_entity.type')and now I can use it. Sep 19, 2017 at 16:01
Is there a way to return the plugin configuration as well? Sep 19, 2017 at 16:13
I would not know, sorry. Though I would think it should be possible. Can't you access it throught the config service? Perhaps there is a pattern? Sep 19, 2017 at 16:25
Yeah it looks like I could just use the config service, when I thought I would have to look at the plugin definition. Oh well! Now I know anyway. Sep 19, 2017 at 16:45
1The plugin configuration is part of the media type/bundle config entity. cgit.drupalcode.org/media_entity/tree/src/Entity/…, it has getType() to get the plugin, which has getPluginDefinition() and getConfiguration(), you can also use getTypeConfiguration() directly on the media bundle entity– BerdirSep 19, 2017 at 19:23