You are here

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

Create an instance of a validation plugin.

Parameters

string $plugin_id: The id of the setup plugin.

array $configuration: Configuration data for the setup plugin.

Return value

object Required validation plugin instance

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Component\Plugin\Exception\PluginException

Overrides PluginManagerBase::createInstance

File

src/TfaValidationPluginManager.php, line 84

Class

TfaValidationPluginManager
The validation plugin manager.

Namespace

Drupal\tfa

Code

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')) {

    // 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;
}