Commit 4e363890 authored by xiaohua guan's avatar xiaohua guan Committed by Yas Naoi
Browse files

Issue #3163202 by Xiaohua Guan, yas: Fix the error of K8s Node Allocated...

Issue #3163202 by Xiaohua Guan, yas: Fix the error of K8s Node Allocated Resources block on AWS Cloud pages
parent 39d2c286
Loading
Loading
Loading
Loading
+4 −1
Changes for modules/cloud_service_providers/k8s/src/Plugin/Block/K8sNodeAllocatedResourcesBlock.php: 4 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Drupal\k8s\Plugin\Block;

use Drupal\Core\Form\FormStateInterface;
use Drupal\cloud\Entity\CloudConfig;

/**
 * Provides a block of the allocated resources at a Node.
@@ -53,8 +54,10 @@ class K8sNodeAllocatedResourcesBlock extends K8sBaseBlock {
      return [];
    }

    // If $cloud_context is empty, do nothing.
    $cloud_context = $this->routeMatch->getParameter('cloud_context');
    if (!CloudConfig::checkCloudContext($cloud_context, 'k8s')) {
      return [];
    }

    // If display_view_k8s_node_list_only is checked, do nothing.
    $route_name = $this->routeMatch->getRouteName();
+23 −10
Changes for src/Entity/CloudConfig.php: 23 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -294,21 +294,34 @@ class CloudConfig extends CloudContentEntityBase implements CloudConfigInterface
  }

  /**
   * Check if a specific cloud_context exists.
   *
   * Corresponds with the #machine_name widget type
   * when adding a new CloudConfig.
   * Check if a specific cloud context is valid.
   *
   * @param string $cloud_context
   *   The cloud context.
   * @param string $bundle
   *   The cloud provider type.
   *
   * @return \Drupal\Core\Entity\EntityInterface[]
   *   The cloud service provider (CloudConfig) entities.
   * @return bool
   *   If the cloud context is valid or not.
   */
  public static function checkCloudContext($cloud_context) {
    $entity_type_manager = \Drupal::entityTypeManager();
    $storage = $entity_type_manager->getStorage('cloud_config');
    return $storage->loadByProperties(['cloud_context' => [$cloud_context]]);
  public static function checkCloudContext($cloud_context, $bundle = NULL) {
    if (empty($cloud_context)) {
      return FALSE;
    }

    $cloud_configs = \Drupal::entityTypeManager()
      ->getStorage('cloud_config')
      ->loadByProperties(['cloud_context' => [$cloud_context]]);
    if (empty($cloud_configs)) {
      return FALSE;
    }

    if (empty($bundle)) {
      return TRUE;
    }

    $cloud_config = reset($cloud_configs);
    return $cloud_config->bundle() === $bundle;
  }

  /**