You are here

function composer_deploy_preprocess_update_project_status in Composer Deploy 8

Implements template_preprocess_update_project_status().

File

./composer_deploy.module, line 74

Code

function composer_deploy_preprocess_update_project_status(&$variables) {
  if (empty($variables['versions'])) {
    return;
  }
  $project_type = $variables['project']['project_type'];
  if (!in_array($project_type, [
    'module',
    'theme',
  ])) {
    return;
  }
  $projectData = \Drupal::service('extension.list.' . $project_type)
    ->getExtensionInfo($variables['project']['name']);
  foreach ($variables['versions'] as &$version) {
    $currentVersion = $variables['project']['existing_version'];

    // Replace our current version with the specific hash when on -dev release.
    if (substr($variables['project']['existing_version'], -3) == 'dev') {
      $currentVersion = $projectData['composer_deploy_git_hash'];
    }
    $upstreamVersion = $version['#version']['tag'];

    // When the upstream is using dev, switch to branch tag.
    if (substr($version['#version']['tag'], -3) == 'dev') {
      $upstreamVersion = substr($version['#version']['tag'], 0, -4);
    }

    // Add diff link.
    $diff = Url::fromUri('https://git.drupalcode.org/project/' . $variables['project']['name'] . '/compare/' . $currentVersion . '...' . $upstreamVersion);
    $version['#version']['diff_link'] = $diff
      ->toString();
  }
}