public function WidgetPluginManager::createInstance in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Field/WidgetPluginManager.php \Drupal\Core\Field\WidgetPluginManager::createInstance()
- 9 core/lib/Drupal/Core/Field/WidgetPluginManager.php \Drupal\Core\Field\WidgetPluginManager::createInstance()
Creates a pre-configured instance of a plugin.
Parameters
string $plugin_id: The ID of the plugin being instantiated.
array $configuration: An array of configuration relevant to the plugin instance.
Return value
object A fully configured plugin instance.
Throws
\Drupal\Component\Plugin\Exception\PluginException If the instance cannot be created, such as if the ID is invalid.
Overrides PluginManagerBase::createInstance
1 call to WidgetPluginManager::createInstance()
- WidgetPluginManager::getInstance in core/
lib/ Drupal/ Core/ Field/ WidgetPluginManager.php - Overrides PluginManagerBase::getInstance().
File
- core/
lib/ Drupal/ Core/ Field/ WidgetPluginManager.php, line 116
Class
- WidgetPluginManager
- Plugin type manager for field widgets.
Namespace
Drupal\Core\FieldCode
public function createInstance($plugin_id, array $configuration = []) {
$plugin_definition = $this
->getDefinition($plugin_id);
$plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition);
// If the plugin provides a factory method, pass the container to it.
if (is_subclass_of($plugin_class, 'Drupal\\Core\\Plugin\\ContainerFactoryPluginInterface')) {
return $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition);
}
return new $plugin_class($plugin_id, $plugin_definition, $configuration['field_definition'], $configuration['settings'], $configuration['third_party_settings']);
}