You are here

public function GeneratorForm::submitForm in AT Tools 8.3

Same name and namespace in other branches
  1. 8.2 at_theme_generator/src/Form/GeneratorForm.php \Drupal\at_theme_generator\Form\GeneratorForm::submitForm()

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

at_theme_generator/src/Form/GeneratorForm.php, line 405

Class

GeneratorForm
Generator form.

Namespace

Drupal\at_theme_generator\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();

  // Don't let this timeout easily.
  set_time_limit(60);
  if (!empty($values['generate']['generate_machine_name'])) {

    // Generate theme.
    if (isset($values['generate']['generate_type']) && !empty($values['generate']['generate_type'])) {
      $type = $values['generate']['generate_type'] . 'Generator';
      $tgt = new ThemeGeneratorTypes($values);
      $tgt
        ->{$type}();
    }
    else {
      drupal_set_message(t('Bummer, something went wrong. Please try again or contact support.'), 'error');
    }

    // Set messages.
    $tg = new ThemeGenerator($values);
    $target = $tg
      ->targetDirectory();
    $friendly_name = Html::escape($values['generate']['generate_friendly_name']);
    $machine_name = $values['generate']['generate_machine_name'];
    $logger_message = t('A new theme <b>@theme_name</b>, with then machine name: <code><b>@machine_name</b></code>, has been generated.', [
      '@theme_name' => $friendly_name,
      '@machine_name' => $machine_name,
    ]);
    \Drupal::logger('at_generator')
      ->notice($logger_message);

    // Message for the user.
    $final_instructions = 'Click the List tab to view the themes list to enable your new theme.';
    if ($values['generate']['options']['generate_directory'] === 'public://') {

      //$target = PublicStream::basePath() . '/generated_themes/' . $machine_name;
      $final_instructions = 'You will need to move the theme to your sites /themes directory before you can enable it.';
    }
    drupal_set_message(t("<p>A new theme <b>@theme_name</b>, with then machine name: <code><b>@machine_name</b></code>, has been generated.</p><p>You can find your theme here: <code>@target</code></p><p>@final_instructions</p>", [
      '@theme_name' => $friendly_name,
      '@machine_name' => $machine_name,
      '@target' => $target,
      '@final_instructions' => $final_instructions,
    ]), 'status');

    // Refresh data.
    system_list_reset();
    \Drupal::service('theme_handler')
      ->rebuildThemeData();
  }
  else {
    drupal_set_message(t('Bummer, something went wrong with the machine name, please try again or contact support.'), 'error');
  }
}