Commit 04ef1617 authored by Yas Naoi's avatar Yas Naoi
Browse files

Issue #3295095 by yas, Ryo Yamashita: Fix an error: "Cannot load cloud service...

Issue #3295095 by yas, Ryo Yamashita: Fix an error: "Cannot load cloud service provider plugin: (CloudConfig::$cloud_context)" in the login form of the SPA
parent a643f33e
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -4667,9 +4667,12 @@ function aws_cloud_get_instance_types($cloud_context, $refresh = TRUE): array {
    else {
      // Cannot load cloud service provider (CloudConfig) entity.
      // Show an error to the user.
      \Drupal::messenger()->addError(t('Cannot load cloud service provider plugin: %cloud_context (CloudConfig::$cloud_context)', [
        '%cloud_context' => $cloud_context,
      ]));

      $message = t('Cannot load cloud service provider plugin: %cloud_context ($cloud_context) at aws_cloud_get_instance_types()', [
        '%cloud_context' => !empty($cloud_context) ? $cloud_context : '<Empty>',
      ]);
      \Drupal::messenger()->addError($message);
      \Drupal::logger('cloud')->error($message);
    }
  }
  catch (\Exception $e) {
+8 −12
Original line number Diff line number Diff line
@@ -107,18 +107,16 @@ class CloudProviderLink extends MenuLinkDefault {
  public function getTitle(): string {
    $title = $this->t('Cloud service providers')->__toString();
    $cloud_context = $this->routeMatch->getParameter('cloud_context');
    if ($cloud_context !== NULL) {
    if (!empty($cloud_context)) {
      try {
        $this->cloudConfigPluginManager->setCloudContext($cloud_context);
        $config = $this->cloudConfigPluginManager->loadConfigEntity();
        $title = $config->getName();
      }
      catch (\Exception $e) {
        $message = $this->t(
          'Cannot load cloud service provider plugin: %cloud_context (CloudConfig::$cloud_context)', [
            '%cloud_context' => $cloud_context,
          ]
        );
        $message = $this->t('Cannot load cloud service provider plugin: %cloud_context ($cloud_context) at Drupal\cloud\Plugin\Menu\CloudProviderLink::getTitle()', [
          '%cloud_context' => !empty($cloud_context) ? $cloud_context : '<Empty>',
        ]);
        $this->messenger->addError($message);
        $this->logger('cloud')->error($message);
      }
@@ -132,17 +130,15 @@ class CloudProviderLink extends MenuLinkDefault {
  public function getRouteName(): string {
    $route = 'view.cloud_config.list';
    $cloud_context = $this->routeMatch->getParameter('cloud_context');
    if ($cloud_context !== NULL) {
    if (!empty($cloud_context)) {
      try {
        $this->cloudConfigPluginManager->setCloudContext($cloud_context);
        $route = $this->cloudConfigPluginManager->getInstanceCollectionTemplateName();
      }
      catch (\Exception $e) {
        $message = $this->t(
          'Cannot load cloud service provider plugin: %cloud_context (CloudConfig::$cloud_context)', [
            '%cloud_context' => $cloud_context,
          ]
        );
        $message = $this->t('Cannot load cloud service provider plugin: %cloud_context ($cloud_context) at Drupal\cloud\Plugin\Menu\getRouteName()', [
          '%cloud_context' => !empty($cloud_context) ? $cloud_context : '<Empty>',
        ]);
        $this->messenger->addError($message);
        $this->logger('cloud')->error($message);
      }
+9 −6
Original line number Diff line number Diff line
@@ -122,7 +122,11 @@ class CloudConfigPluginManager extends CloudPluginManager implements CloudConfig
    if (empty($this->plugin)) {
      // DO NOT translate the message.
      // @see https://www.drupal.org/docs/develop/coding-standards/php-exceptions
      throw new CloudConfigPluginException("Cannot load cloud service provider plugin for '{$this->cloudContext}'");
      $message = $this->t('Cannot load cloud service provider plugin: %cloud_context ($cloud_context) at Drupal\cloud\Plugin\cloud\config\CloudConfigPluginManager::setCloudContext()', [
        '%cloud_context' => !empty($cloud_context) ? $cloud_context : '<Empty>',
      ]);
      $this->logger('cloud')->error($message);
      throw new CloudConfigPluginException($message);
    }
  }

@@ -155,11 +159,10 @@ class CloudConfigPluginManager extends CloudPluginManager implements CloudConfig
      ? $this->plugin->loadConfigEntity($this->cloudContext) : NULL;

    if (empty($config_entity)) {
      $message = $this->t(
        'Cannot load cloud service provider plugin: %cloud_context (CloudConfig::$cloudContext)', [
          '%cloud_context' => $this->cloudContext ?? 'undefined',
        ]
      );
      $message = $this->t('Cannot load cloud service provider plugin: %cloud_context (CloudConfig::$cloud_context) at ', [
        '%cloud_context' => !empty($this->cloud_context) ? $this->cloud_context : '<Empty>',
      ]);
      $this->logger('cloud')->error($message);
      throw new CloudConfigPluginException($message);
    }
    return $config_entity;