Add a warning when K8s Resource Path field is empty at the K8s launch template launch confirmation page

Issue fork cloud-3212126

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

XLD created an issue. See original summary.

XLD’s picture

Status: Active » Needs review
FileSize
1.41 KB
yas’s picture

Status: Needs review » Needs work
FileSize
422.81 KB

@XLD

Thank you for adding the warning message. I posted my new comment above. Also, can you hide the Launch button as the following screenshot? Thanks

launch.png

XLD’s picture

Status: Needs work » Needs review
FileSize
1.73 KB
yas’s picture

Status: Needs review » Needs work

@XLD

Thank you for the update. I tested the patch at #5 and found the following error:

TypeError: array_search(): Argument #2 ($haystack) must be of type array, null given in array_search() (line 2077 of /var/www/html/web/modules/contrib/cloud/modules/cloud_service_providers/k8s/k8s.module)
#0 /var/www/html/web/modules/contrib/cloud/modules/cloud_service_providers/k8s/k8s.module(2077): array_search()
#1 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(539): k8s_form_cloud_server_template_k8s_launch_form_alter()
#2 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(836): Drupal\Core\Extension\ModuleHandler->alter()
#3 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(279): Drupal\Core\Form\FormBuilder->prepareForm()
#4 /var/www/html/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm()
#5 [internal function]: Drupal\Core\Controller\FormController->getContentResult()

So I think we need to add the validation code in k8s_form_cloud_server_template_k8s_delete_form_submit() as follows:

diff --git a/modules/cloud_service_providers/k8s/k8s.module b/modules/cloud_service_providers/k8s/k8s.module
index f6066f67..3629e87b 100644
--- a/modules/cloud_service_providers/k8s/k8s.module
+++ b/modules/cloud_service_providers/k8s/k8s.module
@@ -2074,6 +2074,9 @@ function k8s_form_cloud_server_template_k8s_delete_form_submit(array &$form, For
  * Implements hook_form_BASE_FORM_ID_alter().
  */
 function k8s_form_cloud_server_template_k8s_launch_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
+  if (empty($form['actions']['submit']['#submit'])) {
+    return;
+  }
   $index = array_search('::submitForm', $form['actions']['submit']['#submit']);
   array_splice($form['actions']['submit']['#submit'], $index, 1, 'k8s_form_cloud_server_template_k8s_launch_form_submit');
 }
XLD’s picture

Status: Needs work » Needs review
FileSize
2.71 KB

@yas
Thank you for pointing that out. I've added the validation as suggested.

yas credited Masami.

yas’s picture

Status: Needs review » Reviewed & tested by the community

@XLD

Thank you for the update. I'll merge the patch to 8.x-2.x and 3.x and close this issue as Fixed.

  • yas committed 7bc16bb on 8.x-2.x authored by XLD
    Issue #3212126 by XLD, yas, Masami: Add a warning when K8s Resource Path...

  • yas committed 8b9937a on 3.x authored by XLD
    Issue #3212126 by XLD, yas, Masami: Add a warning when K8s Resource Path...

yas’s picture

Title: Add a warning when K8s Resource Path field is empty at the K8s launch template launch confirmation page (K8s)) » Add a warning when K8s Resource Path field is empty at the K8s launch template launch confirmation page (K8s)
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.