From aa79c93b130bbaea551352224b3e1fac0abec0ea Mon Sep 17 00:00:00 2001
From: Aaron Bauman <aaron@messageagency.com>
Date: Mon, 11 Mar 2019 13:54:13 -0400
Subject: [PATCH] Add 'no auth providers' message when plugins are missing

---
 src/Entity/SalesforceAuthConfig.php | 6 ++++--
 src/Form/SalesforceAuthForm.php     | 5 +++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/Entity/SalesforceAuthConfig.php b/src/Entity/SalesforceAuthConfig.php
index e784e68c..2d96212c 100644
--- a/src/Entity/SalesforceAuthConfig.php
+++ b/src/Entity/SalesforceAuthConfig.php
@@ -140,11 +140,13 @@ class SalesforceAuthConfig extends ConfigEntityBase implements EntityInterface {
    *   The list of plugins, indexed by ID.
    */
   public function getPluginsAsOptions() {
-    $options = ['' => t('- Select -')];
     foreach ($this->authManager()->getDefinitions() as $id => $definition) {
       $options[$id] = ($definition['label']);
     }
-    return $options;
+    if (!empty($options)) {
+      return ['' => t('- Select -')] + $options;
+    }
+    return [];
   }
 
 }
diff --git a/src/Form/SalesforceAuthForm.php b/src/Form/SalesforceAuthForm.php
index 51bf499e..b4564c0a 100644
--- a/src/Form/SalesforceAuthForm.php
+++ b/src/Form/SalesforceAuthForm.php
@@ -22,6 +22,11 @@ class SalesforceAuthForm extends EntityForm {
    */
   public function form(array $form, FormStateInterface $form_state) {
     $auth = $this->entity;
+    if (empty($auth->getPluginsAsOptions())) {
+      $this->messenger()->addError('No auth provider plugins found. Please enable an auth provider module, e.g. salesforce_jwt, before adding an auth config.');
+      $form['#access'] = FALSE;
+      return $form;
+    }
     $form_state->setBuildInfo($form_state->getBuildInfo()
       + ['auth_config' => $this->config($auth->getConfigDependencyName())]);
     $form['label'] = [
-- 
GitLab