You are here

public function YamlFormToWebformMigrateManager::requirements in YAML Form 8

Check requirements.

Return value

array An associative array containing error messages.

Overrides YamlFormToWebformMigrateManagerInterface::requirements

File

modules/yamlform_to_webform/src/YamlFormToWebformMigrateManager.php, line 132

Class

YamlFormToWebformMigrateManager
Defines the YAML Form to Webform migrate manager.

Namespace

Drupal\yamlform_to_webform

Code

public function requirements() {
  $requirements = [];

  // Check database.
  $database_type = Database::getConnection('default')
    ->databaseType();
  if ($database_type != 'mysql') {
    $requirements['database'] = $this
      ->t('Database (@type) is not supported. Only sites using MySQL can be migrated.', [
      '@type' => $database_type,
    ]);
  }

  // Check that Webform module exists and is not '8.x-4.x-dev'.
  $files = file_scan_directory('modules/', '/^webform\\.info.yml$/');
  $webform_info_file = reset($files);
  if (empty($webform_info_file)) {
    $requirements['webform'] = $this
      ->t('Webform 8.x-5.x module is missing from the/modules directory.');
  }
  else {
    $webform_info = Yaml::decode(file_get_contents($webform_info_file->uri));
    if (isset($webform_info['version']) && $webform_info['version'] === '8.x-4.x-dev') {
      $requirements['webform'] = $this
        ->t('Webform 8.x-5.x is required. Please download Webform 8.x-5.x.');
    }
  }

  // Check that the Webform module is disabled.
  if ($this->moduleHandler
    ->moduleExists('webform')) {
    $requirements['webform'] = $this
      ->t('Webform module must be disabled.');
  }

  // Check that the Yaml Form module is enabled.
  if (!$this->moduleHandler
    ->moduleExists('yamlform')) {
    $requirements['yamlform'] = $this
      ->t('YAML Form module must be enabled.');
  }

  // Check for unsupported YAML Form modules.
  $modules = $this->moduleHandler
    ->getModuleList();
  foreach ($modules as $module_name => $module_info) {
    if (strpos($module_name, 'yamlform') !== FALSE && !in_array($module_name, $this->yamlformModules)) {
      $t_args = [
        '@name' => $module_name,
        '@title' => $module_info
          ->getName(),
      ];
      $requirements["module.{$module_name}"] = $this
        ->t('The @name module must be uninstalled before performing a migration.', $t_args);
    }
  }
  return $requirements;
}