Skip to content
Snippets Groups Projects
Commit 72a3dce9 authored by xiaohua guan's avatar xiaohua guan Committed by Yas Naoi
Browse files

Issue #3251179 by Xiaohua Guan, yas, onotm: Fix a bug that the master cloud...

Issue #3251179 by Xiaohua Guan, yas, onotm: Fix a bug that the master cloud service providers are displayed in worker's cloud service provider list view
parent ef89860d
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@
* This module handles UI interactions with the cloud system for Cloud Cluster.
*/
use Drupal\cloud_cluster\Entity\CloudClusterWorker;
use Drupal\cloud_cluster\Plugin\rest\resource\CloudClusterWorkerResource;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
......@@ -315,31 +316,42 @@ function cloud_cluster_entity_base_field_info(EntityTypeInterface $entity_type):
* Implements hook_views_query_alter().
*/
function cloud_cluster_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
$regex = implode('_[a-z_]+$|^', cloud_cluster_get_supported_entity_types());
if (!preg_match("/^$regex$/", $view->id())) {
return;
}
// Skips if the view id is not an entity id.
$entity_type_definitions = \Drupal::entityTypeManager()->getDefinitions();
if (empty($entity_type_definitions[$view->id()])) {
if ($view->id() !== 'cloud_config') {
return;
}
$route_match = \Drupal::service('current_route_match');
if ($route_match->getRouteName() === 'views.ajax') {
// When the request is from ajax, get the cloud context from referer.
global $base_url;
// Get the referer url.
$referer = \Drupal::request()->headers->get('referer');
if (!empty($referer)) {
// Get the alias or the referer.
$alias = substr($referer, strlen($base_url));
$url = Url::fromUri('internal:' . $alias);
$params = $url->getRouteParameters();
$cloud_context = $params['cloud_context'] ?? NULL;
$cloud_cluster_worker_id = $params['cloud_cluster_worker'] ?? NULL;
if (empty($cloud_context) || empty($cloud_cluster_worker_id)) {
return;
}
$cloud_cluster_worker = CloudClusterWorker::load($cloud_cluster_worker_id);
}
}
else {
$cloud_context = $route_match->getParameter('cloud_context');
$cloud_cluster_worker = $route_match->getParameter('cloud_cluster_worker');
}
$cloud_cluster_name = $route_match->getParameter(
strpos($view->id(), 'cloud_config') === 0
? 'cloud_context'
: 'cloud_cluster_name'
);
if (empty($cloud_cluster_name)) {
if (empty($cloud_context) || empty($cloud_cluster_worker)) {
return;
}
$query->addWhere(0, 'cloud_cluster_name', $cloud_cluster_name);
$cloud_cluster_worker = $route_match->getParameter('cloud_cluster_worker');
$query->addWhere(0, 'cloud_cluster_name', $cloud_context);
$query->addWhere(0, 'cloud_cluster_worker_name', $cloud_cluster_worker->getName());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment