You are here

public function GenerateForm::validateForm in AT Tools 8

Form validation 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 FormBase::validateForm

File

at_theme_generator/src/Form/GenerateForm.php, line 266
Generator form.

Class

GenerateForm
@file Generator form.

Namespace

Drupal\at_theme_generator\Form

Code

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

  // Validate Theme Generator.
  if (!empty($values['generate']['generate_machine_name'])) {
    $machine_name = $values['generate']['generate_machine_name'];
    $theme_data = $this->themeInfoData;
    if (array_key_exists($machine_name, $theme_data) == FALSE) {
      $target = drupal_get_path('theme', 'at_core') . '/../../' . $machine_name;
      $subtheme_type = $values['generate']['generate_type'];
      $source = '';
      $source_error = '';
      if ($subtheme_type == 'standard') {
        $source = drupal_get_path('module', 'at_theme_generator') . '/starterkits/starterkit';
      }
      else {
        if ($subtheme_type == 'clone') {
          $source = drupal_get_path('theme', $values['generate']['generate_clone_source']);
          $source_error = 'generate][generate_clone_source';
        }
      }

      // Check if directories and files exist and are readable/writable etc.
      if (!file_exists($source) && !is_readable($source)) {
        $form_state
          ->setErrorByName($source_error, t('The source theme (starter kit or clone source) can not be found or is not readable:<br /><code>@source</code>', array(
          '@source' => $source,
        )));
      }
      if (!is_writable(dirname($target))) {
        $form_state
          ->setErrorByName('', t('The target directory is not writable, please check permissions on the <code>@target</code> directory.', array(
          '@target' => $target,
        )));
      }
    }
  }
}