You are here

function composer_deploy_system_info_alter in Composer Deploy 8

Same name and namespace in other branches
  1. 7 composer_deploy.module \composer_deploy_system_info_alter()

Parameters

array $info:

\Drupal\Core\Extension\Extension $file:

$type:

File

./composer_deploy.module, line 13

Code

function composer_deploy_system_info_alter(array &$info, Extension $file, $type) {
  $handler =& drupal_static(__FUNCTION__);
  if (!isset($handler)) {
    $drupalFinder = new DrupalFinder();
    if ($drupalFinder
      ->locateRoot(DRUPAL_ROOT)) {
      $handler = ComposerDeployHandler::fromVendorDir($drupalFinder
        ->getVendorDir());
      $prefixes = \Drupal::config('composer_deploy.settings')
        ->get('prefixes');
      if (!empty($prefixes)) {
        if (!in_array('drupal', $prefixes)) {
          $prefixes[] = 'drupal';
        }
        $handler
          ->setPrefixes($prefixes);
      }
    }
    else {
      $handler = FALSE;
      \Drupal::logger('composer_deploy')
        ->error('Unable to locale vendor dir.');
    }
  }
  if (empty($info['version']) && $handler) {
    $project = basename($file
      ->getFilename(), '.info.yml');
    $package = $handler
      ->getPackage($project);
    if ($package) {

      // Skip processing for Drupal submodules. Submodules (e.g. ldap_authentication ldap) are shipped as metapackages.
      if ($package['type'] == 'metapackage') {
        return;
      }
      $info['project'] = $project;
      $info['composer_deploy_git_hash'] = isset($package['source']['reference']) ? $package['source']['reference'] : NULL;
      if (isset($package['extra']['drupal']['version'])) {
        $info['version'] = $package['extra']['drupal']['version'];
      }
      if (isset($package['extra']['drupal']['datestamp'])) {
        $info['datestamp'] = $package['extra']['drupal']['datestamp'];
      }

      // Fallback to other composer metadata
      if (empty($info['datestamp']) && isset($package['time'])) {
        $info['datestamp'] = strtotime($package['time']);
      }
      if (empty($info['version']) && substr($package['version'], 0, 4) == 'dev-') {
        $info['version'] = substr($package['version'], 4) . '-dev';
      }
      elseif (empty($info['version'])) {

        /**
         * @todo: Handle mode version constraints.
         */
        $info['version'] = 'dev';
      }
    }
  }
}