function GenerateTheme::getStarterKitVersion

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Command/GenerateTheme.php \Drupal\Core\Command\GenerateTheme::getStarterKitVersion()
1 call to GenerateTheme::getStarterKitVersion()
GenerateTheme::execute in core/lib/Drupal/Core/Command/GenerateTheme.php

File

core/lib/Drupal/Core/Command/GenerateTheme.php, line 297

Class

GenerateTheme
Generates a new theme based on latest default markup.

Namespace

Drupal\Core\Command

Code

private static function getStarterKitVersion(Extension $theme, SymfonyStyle $io) : string {
  $source_version = $theme->info['version'] ?? '';
  if ($source_version === '') {
    $confirm = new ConfirmationQuestion(sprintf('The source theme %s does not have a version specified. This makes tracking changes in the source theme difficult. Are you sure you want to continue?', $theme->getName()));
    if (!$io->askQuestion($confirm)) {
      throw new \RuntimeException('source version could not be determined');
    }
    $source_version = 'unknown-version';
  }
  if ($source_version === 'VERSION') {
    $source_version = \Drupal::VERSION;
  }
  // A version in the generator string like "9.4.0-dev" is not very helpful.
  // When this occurs, generate a version string that points to a commit.
  if (VersionParser::parseStability($source_version) === 'dev') {
    $git_check = Process::fromShellCommandline('git --help');
    $git_check->run();
    if ($git_check->getExitCode()) {
      throw new \RuntimeException(sprintf('The source theme %s has a development version number (%s). Determining a specific commit is not possible because git is not installed. Either install git or use a tagged release to generate a theme.', $theme->getName(), $source_version));
    }
    // Get the git commit for the source theme.
    $git_get_commit = Process::fromShellCommandline("git rev-list --max-count=1 --abbrev-commit HEAD -C {$theme->getPath()}");
    $git_get_commit->run();
    if (!$git_get_commit->isSuccessful() || $git_get_commit->getOutput() === '') {
      $confirm = new ConfirmationQuestion(sprintf('The source theme %s has a development version number (%s). Because it is not a git checkout, a specific commit could not be identified. This makes tracking changes in the source theme difficult. Are you sure you want to continue?', $theme->getName(), $source_version));
      if (!$io->askQuestion($confirm)) {
        throw new \RuntimeException('source version could not be determined');
      }
      $source_version .= '#unknown-commit';
    }
    else {
      $source_version .= '#' . trim($git_get_commit->getOutput());
    }
  }
  return $source_version;
}

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