Commit 38113066 authored by Yas Naoi's avatar Yas Naoi
Browse files

Issue #3291234 by yas, Xiaohua Guan: Refactor the source code based on Drupal...

Issue #3291234 by yas, Xiaohua Guan: Refactor the source code based on Drupal best practices (5) (Misc)
parent 78abb5c2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2203,7 +2203,7 @@ function aws_cloud_update_8216(): void {
  foreach ($cloud_configs_temp ?: [] as $cloud_config_temp) {

    try {
      $cloud_config_temp = unserialize($cloud_config_temp, ['allowed_classes' => TRUE]);
      $cloud_config_temp = unserialize($cloud_config_temp, ['allowed_classes' => ['CloudConfig']]);
      $params = [
        // Those fields such as 'type', 'name', 'cloud_context'... are not the
        // field_*, so we will access the value via each method.
+2 −10
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ use Drupal\cloud\Entity\CloudLaunchTemplate;
use Drupal\cloud\Traits\CloudContentEntityTrait;
use Drupal\cloud_cluster\Entity\CloudClusterWorker\CloudClusterWorker;
use Drupal\cloud_cluster\Plugin\rest\resource\CloudClusterWorkerResource;
use Drupal\cloud_cluster\Service\CloudClusterServiceInterface;
use Drupal\Component\Serialization\Yaml;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\CssCommand;
@@ -31,15 +32,6 @@ use Drupal\file\Entity\File;
use Drupal\views\Plugin\views\query\QueryPluginBase;
use Drupal\views\ViewExecutable;

define('CLOUD_CLUSTER_SUPPORTED_ENTITY_TYPES', [
  'aws_cloud_*',
  'k8s_*',
  'vmware_*',
  'openstack_*',
  'cloud_config',
  'cloud_launch_template',
]);

/**
 * Implements hook_help().
 */
@@ -441,7 +433,7 @@ function cloud_cluster_menu_local_tasks_alter(&$data, $route_name): void {
 *   The entity type is supported or not.
 */
function cloud_cluster_is_entity_type_supported($entity_type): bool {
  $regex = '^' . implode('$|^', CLOUD_CLUSTER_SUPPORTED_ENTITY_TYPES) . '$';
  $regex = '^' . implode('$|^', CloudClusterServiceInterface::CLOUD_CLUSTER_SUPPORTED_ENTITY_TYPES) . '$';
  $regex = str_replace('_*', '_[a-z_]+', $regex);
  return preg_match("/$regex/", $entity_type);
}
+19 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\cloud_cluster\Service;

/**
 * Provides K8sService interface.
 */
interface CloudClusterServiceInterface {

  public const CLOUD_CLUSTER_SUPPORTED_ENTITY_TYPES = [
    'aws_cloud_*',
    'k8s_*',
    'vmware_*',
    'openstack_*',
    'cloud_config',
    'cloud_launch_template',
  ];

}