Loading modules/cloud_service_providers/k8s/src/Plugin/Block/K8sNodeAllocatedResourcesBlock.php +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 Loading @@ -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. Loading Loading @@ -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(); Loading src/Entity/CloudConfig.php +23 −10 Changes for src/Entity/CloudConfig.php: 23 added lines, 10 removed lines. Original line number Diff line number Diff line Loading @@ -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; } /** Loading Loading
modules/cloud_service_providers/k8s/src/Plugin/Block/K8sNodeAllocatedResourcesBlock.php +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 Loading @@ -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. Loading Loading @@ -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(); Loading
src/Entity/CloudConfig.php +23 −10 Changes for src/Entity/CloudConfig.php: 23 added lines, 10 removed lines. Original line number Diff line number Diff line Loading @@ -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; } /** Loading