function ExtensionInstallCommand::checkRequirements

Runs hook_requirements('install') for the given modules.

Parameters

string[] $modules: The module machine names to check.

\Symfony\Component\Console\Style\SymfonyStyle $io: The output style used to report any failures.

Return value

bool TRUE if all modules meet their installation requirements.

File

core/modules/system/src/Command/ExtensionInstallCommand.php, line 290

Class

ExtensionInstallCommand
Installs modules or themes, resolving and confirming their dependencies.

Namespace

Drupal\system\Command

Code

protected function checkRequirements(array $modules, SymfonyStyle $io) : bool {
  // Make sure the install API is available.
  include_once DRUPAL_ROOT . '/core/includes/install.inc';
  $failed = [];
  foreach ($modules as $module) {
    if (!drupal_check_module($module)) {
      $failed[] = $module;
    }
  }
  // drupal_check_module() reports the specific failures via the messenger;
  // surface them on the console and clear them so they are not rendered
  // again on a subsequent request.
  foreach ($this->messenger
    ->messagesByType(MessengerInterface::TYPE_ERROR) as $message) {
    $io->error((string) $message);
  }
  $this->messenger
    ->deleteByType(MessengerInterface::TYPE_ERROR);
  if (!empty($failed)) {
    $io->error((string) $this->t('The following modules did not meet their installation requirements: @modules.', [
      '@modules' => implode(', ', $failed),
    ]));
    return FALSE;
  }
  return TRUE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.