Loading modules/cloud_service_providers/k8s/src/Form/K8sContentForm.php +4 −2 Original line number Diff line number Diff line Loading @@ -463,9 +463,11 @@ abstract class K8sContentForm extends CloudContentForm implements K8sContentForm $options = []; foreach ($namespaces ?: [] as $namespace) { if ($this->currentUser->hasPermission('view k8s namespace ' . $namespace->getName())) { $name = $namespace->getName(); $options[$name] = $name; } } natcasesort($options); return $options; Loading modules/cloud_service_providers/k8s/src/Form/K8sCreateForm.php +37 −9 Original line number Diff line number Diff line Loading @@ -6,7 +6,10 @@ use Drupal\Component\Serialization\Yaml; use Drupal\Core\Entity\EntityMalformedException; use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Link; use Drupal\Core\Url; use Drupal\k8s\Service\K8sServiceException; use Symfony\Component\HttpFoundation\RedirectResponse; /** * Form controller for the entity create form. Loading Loading @@ -34,6 +37,8 @@ class K8sCreateForm extends K8sContentForm { '#weight' => $weight++, ]; if (method_exists($this->entity, 'getNamespace')) { $options = []; try { $options = $this->getNamespaceOptions(); Loading @@ -42,8 +47,31 @@ class K8sCreateForm extends K8sContentForm { $this->k8sService->handleError($e, $cloud_context, $this->entity); } if (!empty($options) && method_exists($this->entity, 'getNamespace')) { // Redirect to list view if there isn't a namespace which can be used. if (empty($options)) { $this->messenger->addWarning( $this->t('You will not be able to create a K8s @type since you have no accessible K8s namespace.', [ '@type' => $this->entity->getEntityType()->getSingularLabel(), ]) ); if ($this->currentUser->hasPermission('add k8s namespace')) { $add_k8s_namespace = Link::createFromRoute($this->t('create a namespace'), 'entity.k8s_namespace.add_form', [ 'cloud_context' => $cloud_context, ])->toString(); $this->messenger->addWarning($this->t('Try to @add_k8s_namespace or contact your site administrator.', [ '@add_k8s_namespace' => $add_k8s_namespace, ])); } $redirect_url = Url::fromRoute("view.k8s_{$this->getShortEntityTypeNameUnderScore($this->entity)}.list", [ 'cloud_context' => $cloud_context, ]); $redirect = new RedirectResponse($redirect_url->toString()); $redirect->send(); return $form; } $form[$name_underscore]['namespace'] = [ '#type' => 'select', Loading Loading
modules/cloud_service_providers/k8s/src/Form/K8sContentForm.php +4 −2 Original line number Diff line number Diff line Loading @@ -463,9 +463,11 @@ abstract class K8sContentForm extends CloudContentForm implements K8sContentForm $options = []; foreach ($namespaces ?: [] as $namespace) { if ($this->currentUser->hasPermission('view k8s namespace ' . $namespace->getName())) { $name = $namespace->getName(); $options[$name] = $name; } } natcasesort($options); return $options; Loading
modules/cloud_service_providers/k8s/src/Form/K8sCreateForm.php +37 −9 Original line number Diff line number Diff line Loading @@ -6,7 +6,10 @@ use Drupal\Component\Serialization\Yaml; use Drupal\Core\Entity\EntityMalformedException; use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Link; use Drupal\Core\Url; use Drupal\k8s\Service\K8sServiceException; use Symfony\Component\HttpFoundation\RedirectResponse; /** * Form controller for the entity create form. Loading Loading @@ -34,6 +37,8 @@ class K8sCreateForm extends K8sContentForm { '#weight' => $weight++, ]; if (method_exists($this->entity, 'getNamespace')) { $options = []; try { $options = $this->getNamespaceOptions(); Loading @@ -42,8 +47,31 @@ class K8sCreateForm extends K8sContentForm { $this->k8sService->handleError($e, $cloud_context, $this->entity); } if (!empty($options) && method_exists($this->entity, 'getNamespace')) { // Redirect to list view if there isn't a namespace which can be used. if (empty($options)) { $this->messenger->addWarning( $this->t('You will not be able to create a K8s @type since you have no accessible K8s namespace.', [ '@type' => $this->entity->getEntityType()->getSingularLabel(), ]) ); if ($this->currentUser->hasPermission('add k8s namespace')) { $add_k8s_namespace = Link::createFromRoute($this->t('create a namespace'), 'entity.k8s_namespace.add_form', [ 'cloud_context' => $cloud_context, ])->toString(); $this->messenger->addWarning($this->t('Try to @add_k8s_namespace or contact your site administrator.', [ '@add_k8s_namespace' => $add_k8s_namespace, ])); } $redirect_url = Url::fromRoute("view.k8s_{$this->getShortEntityTypeNameUnderScore($this->entity)}.list", [ 'cloud_context' => $cloud_context, ]); $redirect = new RedirectResponse($redirect_url->toString()); $redirect->send(); return $form; } $form[$name_underscore]['namespace'] = [ '#type' => 'select', Loading