You are here

function salesforce_get_auth_provider_requirements in Salesforce Suite 5.0.x

Same name and namespace in other branches
  1. 8.4 salesforce.install \salesforce_get_auth_provider_requirements()
  2. 8.3 salesforce.install \salesforce_get_auth_provider_requirements()

Check to see if an auth provider has been set.

5 calls to salesforce_get_auth_provider_requirements()
salesforce_requirements in ./salesforce.install
Implements hook_requirements().
StatusPageTest::testAuthProviderRequirementsNoConfig in tests/src/Functional/StatusPageTest.php
Test requirements with providers, but no config.
StatusPageTest::testAuthProviderRequirementsNoProviders in tests/src/Functional/StatusPageTest.php
Test requirements when no providers are available.
StatusPageTest::testAuthProviderRequirementsNoToken in tests/src/Functional/StatusPageTest.php
Test requirements with providers and config, but no token.
StatusPageTest::testAuthProviderRequirementsOk in tests/src/Functional/StatusPageTest.php
Test requirements when everything is in place.

File

./salesforce.install, line 62
Salesforce install file.

Code

function salesforce_get_auth_provider_requirements() {
  $requirements = [
    'title' => t('Salesforce Authentication Status'),
    'value' => t('Provider Status'),
  ];

  /** @var \Drupal\salesforce\SalesforceAuthProviderPluginManagerInterface $authMan */
  $authMan = \Drupal::service('plugin.manager.salesforce.auth_providers');
  if (!$authMan
    ->hasProviders()) {
    $requirements += [
      'description' => t('No auth providers have been created. Please <a href="@href">create an auth provider</a> to connect to Salesforce.', [
        '@href' => Url::fromRoute('entity.salesforce_auth.add_form')
          ->toString(),
      ]),
      'severity' => REQUIREMENT_ERROR,
    ];
  }
  elseif (!$authMan
    ->getConfig()) {
    $requirements += [
      'description' => t('Default auth provider has not been set. Please <a href="@href">choose an auth provider</a> to connect to Salesforce.', [
        '@href' => Url::fromRoute('salesforce.auth_config')
          ->toString(),
      ]),
      'severity' => REQUIREMENT_ERROR,
    ];
  }
  else {
    $failMessage = t('Salesforce authentication failed. Please <a href="@href">check your auth provider settings</a> to connect to Salesforce.', [
      '@href' => Url::fromRoute('entity.salesforce_auth.edit_form', [
        'salesforce_auth' => $authMan
          ->getConfig()
          ->id(),
      ])
        ->toString(),
    ]);
    try {
      if (!$authMan
        ->getToken()) {
        $requirements += [
          'description' => $failMessage,
          'severity' => REQUIREMENT_ERROR,
        ];
      }
    } catch (Exception $e) {
      $requirements += [
        'description' => $failMessage,
        'severity' => REQUIREMENT_ERROR,
      ];
    }
  }
  if (empty($requirements['severity'])) {
    $requirements += [
      'severity' => REQUIREMENT_OK,
    ];
  }
  return $requirements;
}