You are here

function composer_deploy_system_info_alter in Composer Deploy 7

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

Implements hook_system_info_alter().

File

./composer_deploy.module, line 10
Hook implementations for this module.

Code

function composer_deploy_system_info_alter(&$info, $file, $type) {
  $handler =& drupal_static(__FUNCTION__);
  if (!isset($handler)) {
    module_load_include('php', 'composer_deploy', 'includes/ComposerDeployHandler');
    $handler = \Drupal\composer_deploy\ComposerDeployHandler::fromVendorDir(variable_get('composer_deploy_vendor_dir', '../vendor'));
  }
  if (empty($info['version'])) {
    $project = basename($file->name, '.info');
    $package = $handler
      ->getPackage($project);
    if ($package) {
      $info['project'] = $project;
      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'])) {
        $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';
      }
    }
  }
}