You are here

public function YamlFormToWebformMigrateForm::submitForm in YAML Form 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

modules/yamlform_to_webform/src/Form/YamlFormToWebformMigrateForm.php, line 132

Class

YamlFormToWebformMigrateForm
YAML Form to Webform migrate form.

Namespace

Drupal\yamlform_to_webform\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $this->migrateManager
    ->migrate();

  // DEBUG:

  /*
  $messages = $this->migrateManager->migrate();
  $build = [
    'database' => [
      '#theme' => 'item_list',
      '#items' => $messages,
      '#title' => $this->t('Database changes'),
    ],
  ];
  drupal_set_message($build);
  */

  // Clear Drupal's cache via a new request.
  // @see drush_cache_rebuild()
  $autoloader = (require DRUPAL_ROOT . '/autoload.php');
  require_once DRUPAL_ROOT . '/core/includes/utility.inc';
  $request = Request::createFromGlobals();
  DrupalKernel::bootEnvironment();
  $root = DRUPAL_ROOT;
  $site_path = DrupalKernel::findSitePath($request);
  Settings::initialize($root, $site_path, $autoloader);
  drupal_rebuild($autoloader, $request);

  // Redirect the new Webform page using a simple header redirect because
  // Drupal routing has not been updated.
  drupal_set_message($this
    ->t("YAML Form to Webform migration has completed. Please review your forms and entire site."));
  global $base_url;
  header("Location: {$base_url}/admin/structure/webform");
  die;
}