You are here

public static function PluginBase::create in Drupal 7 to 8/9 Module Upgrader 8

Creates an instance of the plugin.

Parameters

\Symfony\Component\DependencyInjection\ContainerInterface $container: The container to pull out services used in the plugin.

array $configuration: A configuration array containing information about the plugin instance.

string $plugin_id: The plugin ID for the plugin instance.

mixed $plugin_definition: The plugin implementation definition.

Return value

static Returns an instance of this plugin.

Overrides ContainerFactoryPluginInterface::create

2 methods override PluginBase::create()
Grep::create in src/Plugin/DMU/Converter/Grep.php
Creates an instance of the plugin.
UserHooks::create in src/Plugin/DMU/Converter/UserHooks.php
Creates an instance of the plugin.

File

src/PluginBase.php, line 33

Class

PluginBase
Base class for all DMU plugin types, pulling string translation and logging services from the container by default.

Namespace

Drupal\drupalmoduleupgrader

Code

public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
  $arguments = [
    $configuration,
    $plugin_id,
    $plugin_definition,
    // Always include the string translation and logging services.
    $container
      ->get('string_translation'),
    $container
      ->get('logger.factory')
      ->get('drupalmoduleupgrader'),
  ];

  // Pull any declared dependencies out of the container.
  if (isset($plugin_definition['dependencies'])) {
    foreach ($plugin_definition['dependencies'] as $dependency) {
      $arguments[] = $container
        ->get($dependency);
    }
  }
  return (new \ReflectionClass(get_called_class()))
    ->newInstanceArgs($arguments);
}