You are here

protected function WebformCliService::drush_webform_composer_set_libraries in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Commands/WebformCliService.php \Drupal\webform\Commands\WebformCliService::drush_webform_composer_set_libraries()

Set composer libraries.

Parameters

object $repositories: Composer repositories.

object $require: Composer require.

2 calls to WebformCliService::drush_webform_composer_set_libraries()
WebformCliService::drush_webform_composer_update in src/Commands/WebformCliService.php
Implements drush_hook_COMMAND().
WebformCliService::drush_webform_libraries_composer in src/Commands/WebformCliService.php
Implements drush_hook_COMMAND().

File

src/Commands/WebformCliService.php, line 1188

Class

WebformCliService
Drush version agnostic commands.

Namespace

Drupal\webform\Commands

Code

protected function drush_webform_composer_set_libraries(&$repositories, &$require) {

  /** @var \Drupal\webform\WebformLibrariesManagerInterface $libraries_manager */
  $libraries_manager = \Drupal::service('webform.libraries_manager');
  $libraries = $libraries_manager
    ->getLibraries(TRUE);
  foreach ($libraries as $library_name => $library) {

    // Never overwrite existing repositories.
    if (isset($repositories->{$library_name})) {
      continue;
    }

    // Skip libraries installed by other modules.
    if (!empty($library['module'])) {
      continue;
    }
    $dist_url = $library['download_url']
      ->toString();
    if (preg_match('/\\.zip$/', $dist_url)) {
      $dist_type = 'zip';
    }
    elseif (preg_match('/\\.tgz$/', $dist_url)) {
      $dist_type = 'tar';
    }
    else {
      $dist_type = 'file';
    }
    $package_version = $library['version'];
    if (strpos($library_name, '/') !== FALSE) {
      $package_name = $library_name;
    }
    elseif (strpos($library_name, '.') !== FALSE) {
      $package_name = str_replace('.', '/', $library_name);
    }
    else {
      $package_name = "{$library_name}/{$library_name}";
    }
    $repositories->{$library_name} = [
      '_webform' => TRUE,
      'type' => 'package',
      'package' => [
        'name' => $package_name,
        'version' => $package_version,
        'type' => 'drupal-library',
        'extra' => [
          'installer-name' => $library_name,
        ],
        'dist' => [
          'url' => $dist_url,
          'type' => $dist_type,
        ],
        'require' => [
          'composer/installers' => '~1.0',
        ],
      ],
    ];
    $require->{$package_name} = '*';
  }
  $repositories = WebformObjectHelper::sortByProperty($repositories);
  $require = WebformObjectHelper::sortByProperty($require);
}