You are here

public function SettingsForm::validateForm in Habitat 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

habitat_ui/src/Form/SettingsForm.php, line 104
Contains \Drupal\habitat_ui\Form\SettingsForm.

Class

SettingsForm
Defines a form that configures habitat settings.

Namespace

Drupal\habitat_ui\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $config = $this
    ->config('habitat.settings');
  $habitats = $config
    ->get('habitat_habitats');
  $module_data = system_rebuild_module_data();
  foreach ($habitats as $habitat) {
    foreach (array(
      'install',
      'uninstall',
    ) as $type) {
      $modules = array_filter(array_map('trim', explode("\n", $form_state
        ->getValue($type . '_' . $habitat))));
      $module_list = $modules ? array_combine($modules, $modules) : array();
      if ($missing_modules = array_diff_key($module_list, $module_data)) {
        $form_state
          ->setErrorByName($type . '_' . $habitat, t('Cannot set @habitat @typeed modules due to missing modules @modules.', array(
          '@habitat' => $habitat,
          '@type' => $type,
          '@modules' => implode(', ', $missing_modules),
        )));
      }
    }
  }
}