You are here

function varbase_update_helper_checklistapi_form_submit in Varbase Core 8.7

Same name and namespace in other branches
  1. 8.8 modules/varbase_update_helper/varbase_update_helper.module \varbase_update_helper_checklistapi_form_submit()
  2. 8.6 modules/varbase_update_helper/varbase_update_helper.module \varbase_update_helper_checklistapi_form_submit()
  3. 9.0.x modules/varbase_update_helper/varbase_update_helper.module \varbase_update_helper_checklistapi_form_submit()

Implements hook_checklistapti_form_submit().

1 string reference to 'varbase_update_helper_checklistapi_form_submit'
varbase_update_helper_form_alter in modules/varbase_update_helper/varbase_update_helper.module
Implements hook_form_alter().

File

modules/varbase_update_helper/varbase_update_helper.module, line 48
Contains varbase_update_helper.module.

Code

function varbase_update_helper_checklistapi_form_submit(array $form, FormStateInterface $form_state) {
  $messenger = \Drupal::messenger();
  $checklistapi = $form_state
    ->getValue('checklistapi');
  foreach ($checklistapi as $key => $updateset) {
    if ($key == "checklistapi__active_tab") {
      continue;
    }
    if (is_array($updateset) && !empty($updateset)) {
      foreach ($updateset as $update => $status) {
        $update_key = str_replace('.', '_', $update);
        $entity = Update::load($update_key);
        $entityStatus = $entity && $entity
          ->wasSuccessfulByHook() ? TRUE : FALSE;
        if ($entityStatus) {
          continue;
        }
        if ($status) {
          $update_data = explode(":", $update);
          module_load_install($update_data[0]);
          if (function_exists($update_data[1])) {
            call_user_func($update_data[1], FALSE);
          }
          else {
            $checklistapi[$key][$update] = 0;
            $messenger
              ->addWarning(t("Couldn't find an update hook: %update_hook. Please verify the update hook name.", [
              "%update_hook" => $update_data[1],
            ]));
          }
        }
      }
    }
  }
  $checklist = $form['#checklist'];

  // Save progress.
  $checklist
    ->saveProgress($checklistapi);

  // Preserve the active tab after submission.
  $form_state
    ->setRedirect($checklist
    ->getRouteName(), [], [
    'fragment' => $checklistapi['checklistapi__active_tab'],
  ]);
}