You are here

protected function OpenIDConnectSettingsForm::getClients in OpenID Connect / OAuth client 8

Return array of OpenID Connect client plugins.

As the list of clients is used several times during form submission, we are using this little helper method and a static collection of initialized client plugins for this form.

Return value

\Drupal\openid_connect\Plugin\OpenIDConnectClientInterface[] Associative array of OpenID Connect client plugins with client IDs as keys and the corresponding initialized client plugins as values.

Throws

\Drupal\Component\Plugin\Exception\PluginException

3 calls to OpenIDConnectSettingsForm::getClients()
OpenIDConnectSettingsForm::buildForm in src/Form/OpenIDConnectSettingsForm.php
Form constructor.
OpenIDConnectSettingsForm::submitForm in src/Form/OpenIDConnectSettingsForm.php
Form submission handler.
OpenIDConnectSettingsForm::validateForm in src/Form/OpenIDConnectSettingsForm.php
Form validation handler.

File

src/Form/OpenIDConnectSettingsForm.php, line 321

Class

OpenIDConnectSettingsForm
Provides the OpenID Connect settings form.

Namespace

Drupal\openid_connect\Form

Code

protected function getClients() {
  if (!isset(self::$clients)) {
    $clients = [];
    $definitions = $this->pluginManager
      ->getDefinitions();
    ksort($definitions);
    foreach ($definitions as $client_name => $client_plugin) {
      $configuration = $this
        ->configFactory()
        ->getEditable('openid_connect.settings.' . $client_name)
        ->get('settings');

      /** @var \Drupal\openid_connect\Plugin\OpenIDConnectClientInterface $client */
      $client = $this->pluginManager
        ->createInstance($client_name, $configuration ?: []);
      $clients[$client_name] = $client;
    }
    self::$clients = $clients;
  }
  return self::$clients;
}