You are here

protected function PackageController::buildRequiredVersion in Composer Manager 8

Builds the render array for the required version column.

Parameters

string $contraint: The package constraint.

array $required_by: The names of dependent packages.

Return value

array The requirements render array.

1 call to PackageController::buildRequiredVersion()
PackageController::page in src/Controller/PackageController.php
Shows the status of all required packages.

File

src/Controller/PackageController.php, line 180

Class

PackageController
Controller for displaying the list of required packages.

Namespace

Drupal\composer_manager\Controller

Code

protected function buildRequiredVersion($constraint, array $required_by) {

  // Filter out non-Drupal packages.
  $drupal_required_by = array_filter($required_by, function ($package_name) {
    return strpos($package_name, 'drupal/') !== FALSE;
  });
  if (empty($required_by)) {
    $constraint = $this
      ->t('No longer required');
    $description = $this
      ->t('Package will be removed on the next Composer update');
  }
  elseif (empty($drupal_required_by)) {

    // The package is here as a requirement of other packages, list them.
    $constraint = $this
      ->t('N/A');
    $description = $this
      ->t('Required by: ') . implode(', ', $required_by);
  }
  else {
    if (!isset($this->moduleData)) {
      $this->moduleData = system_get_info('module');
    }
    $modules = [];
    foreach ($drupal_required_by as $package_name) {
      $name_parts = explode('/', $package_name);
      $module_name = $name_parts[1];
      if ($module_name == 'core') {
        $modules[] = $this
          ->t('Drupal');
      }
      elseif (isset($this->moduleData[$module_name])) {
        $modules[] = $this->moduleData[$module_name]['name'];
      }
      else {
        $modules[] = $module_name;
      }
    }
    $description = $this
      ->t('Required by: ') . implode(', ', $modules);
  }
  $required_version = [];
  $required_version[] = [
    '#plain_text' => $constraint,
  ];
  $required_version[] = [
    '#prefix' => '<div class="description">',
    '#plain_text' => $description,
    '#suffix' => '</div>',
  ];
  return $required_version;
}