function InstallCommand::validateProfile

Same name in other branches
  1. 9 core/lib/Drupal/Core/Command/InstallCommand.php \Drupal\Core\Command\InstallCommand::validateProfile()
  2. 10 core/lib/Drupal/Core/Command/InstallCommand.php \Drupal\Core\Command\InstallCommand::validateProfile()
  3. 11.x core/lib/Drupal/Core/Command/InstallCommand.php \Drupal\Core\Command\InstallCommand::validateProfile()

Validates a user provided install profile.

Parameters

string $install_profile: Install profile to validate.

\Symfony\Component\Console\Style\SymfonyStyle $io: Symfony style output decorator.

Return value

bool TRUE if the profile is valid, FALSE if not.

1 call to InstallCommand::validateProfile()
InstallCommand::execute in core/lib/Drupal/Core/Command/InstallCommand.php

File

core/lib/Drupal/Core/Command/InstallCommand.php, line 284

Class

InstallCommand
Installs a Drupal site for local testing/development.

Namespace

Drupal\Core\Command

Code

protected function validateProfile($install_profile, SymfonyStyle $io) {
    // Allow people to install hidden and non-distribution profiles if they
    // supply the argument.
    $profiles = $this->getProfiles(TRUE, FALSE);
    if (!isset($profiles[$install_profile])) {
        $error_msg = sprintf("'%s' is not a valid install profile.", $install_profile);
        $alternatives = [];
        foreach (array_keys($profiles) as $profile_name) {
            $lev = levenshtein($install_profile, $profile_name);
            if ($lev <= strlen($profile_name) / 4 || FALSE !== strpos($profile_name, $install_profile)) {
                $alternatives[] = $profile_name;
            }
        }
        if (!empty($alternatives)) {
            $error_msg .= sprintf(" Did you mean '%s'?", implode("' or '", $alternatives));
        }
        $io->getErrorStyle()
            ->error($error_msg);
        return FALSE;
    }
    return TRUE;
}

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