You are here

public function TfaLoginPluginManager::createInstance in Two-factor Authentication (TFA) 8

Create an instance of a plugin.

Parameters

string $plugin_id: The id of the setup plugin.

array $configuration: Configuration data for the setup plugin.

Return value

object The plugin instance.

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Component\Plugin\Exception\PluginException

Overrides PluginManagerBase::createInstance

1 call to TfaLoginPluginManager::createInstance()
TfaLoginPluginManager::getPlugins in src/TfaLoginPluginManager.php
Returns an array of enabled login plugins.

File

src/TfaLoginPluginManager.php, line 90

Class

TfaLoginPluginManager
The login plugin manager.

Namespace

Drupal\tfa

Code

public function createInstance($plugin_id, array $configuration = []) {
  $plugin_definition = $this
    ->getDefinition($plugin_id);

  /** @var \Drupal\tfa\Plugin\TfaBasePlugin $plugin_class */
  $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')) {

    // phpcs:ignore DrupalPractice.Objects.GlobalDrupal.GlobalDrupal
    $plugin = $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition, $this->userData, $this->encryptionProfileManager, $this->encryptService);
  }
  else {
    $plugin = new $plugin_class($configuration, $plugin_id, $plugin_definition, $this->userData, $this->encryptionProfileManager, $this->encryptService);
  }
  return $plugin;
}