You are here

protected function PurgeConfigurationsForm::buildRow in Easy Install 8.7

Same name and namespace in other branches
  1. 8.9 src/Form/PurgeConfigurationsForm.php \Drupal\easy_install\Form\PurgeConfigurationsForm::buildRow()
  2. 8.10 src/Form/PurgeConfigurationsForm.php \Drupal\easy_install\Form\PurgeConfigurationsForm::buildRow()
  3. 8.5 src/Form/PurgeConfigurationsForm.php \Drupal\easy_install\Form\PurgeConfigurationsForm::buildRow()
  4. 8.6 src/Form/PurgeConfigurationsForm.php \Drupal\easy_install\Form\PurgeConfigurationsForm::buildRow()
  5. 8.8 src/Form/PurgeConfigurationsForm.php \Drupal\easy_install\Form\PurgeConfigurationsForm::buildRow()

Builds a table row for the system modules page.

Parameters

array $modules: The list existing modules.

\Drupal\Core\Extension\Extension $module: The module for which to build the form row.

string $distribution: Drupal profile distribution name.

Return value

array The form row for the given module.

1 call to PurgeConfigurationsForm::buildRow()
PurgeConfigurationsForm::buildForm in src/Form/PurgeConfigurationsForm.php
Form constructor.

File

src/Form/PurgeConfigurationsForm.php, line 202

Class

PurgeConfigurationsForm
Provides module installation interface.

Namespace

Drupal\easy_install\Form

Code

protected function buildRow(array $modules, Extension $module, $distribution) {

  // Set the basic properties.
  $row['#required'] = [];
  $row['#requires'] = [];
  $row['#required_by'] = [];
  $row['name']['#markup'] = $module->info['name'];
  $row['description']['#markup'] = $this
    ->t('@desc', [
    '@desc' => $module->info['description'],
  ]);
  $row['version']['#markup'] = $module->info['version'];

  // Generate link for module's help page. Assume that if a hook_help()
  // implementation exists then the module provides an overview page, rather
  // than checking to see if the page exists, which is costly.
  if ($this->moduleHandler
    ->moduleExists('help') && $module->status && in_array($module
    ->getName(), $this->moduleHandler
    ->getImplementations('help'))) {
    $row['links']['help'] = [
      '#type' => 'link',
      '#title' => $this
        ->t('Help'),
      '#url' => Url::fromRoute('help.page', [
        'name' => $module
          ->getName(),
      ]),
      '#options' => [
        'attributes' => [
          'class' => [
            'module-link',
            'module-link-help',
          ],
          'title' => $this
            ->t('Help'),
        ],
      ],
    ];
  }

  // Generate link for module's permission, if the user has access to it.
  if ($module->status && $this->currentUser
    ->hasPermission('administer permissions') && $this->permissionHandler
    ->moduleProvidesPermissions($module
    ->getName())) {
    $row['links']['permissions'] = [
      '#type' => 'link',
      '#title' => $this
        ->t('Permissions'),
      '#url' => Url::fromRoute('user.admin_permissions'),
      '#options' => [
        'fragment' => 'module-' . $module
          ->getName(),
        'attributes' => [
          'class' => [
            'module-link',
            'module-link-permissions',
          ],
          'title' => $this
            ->t('Configure permissions'),
        ],
      ],
    ];
  }

  // Generate link for module's configuration page, if it has one.
  if ($module->status && isset($module->info['configure'])) {
    $route_parameters = isset($module->info['configure_parameters']) ? $module->info['configure_parameters'] : [];
    if ($this->accessManager
      ->checkNamedRoute($module->info['configure'], $route_parameters, $this->currentUser)) {
      $row['links']['configure'] = [
        '#type' => 'link',
        '#title' => $this
          ->t('Configure <span class="visually-hidden">the @module module</span>', [
          '@module' => $module->info['name'],
        ]),
        '#url' => Url::fromRoute($module->info['configure'], $route_parameters),
        '#options' => [
          'attributes' => [
            'class' => [
              'module-link',
              'module-link-configure',
            ],
          ],
        ],
      ];
    }
  }

  // Present a checkbox for installing and indicating the status of a module.
  $row['enable'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Install'),
    '#default_value' => (bool) $module->status,
    '#disabled' => (bool) $module->status,
  ];

  // Disable the checkbox for required modules.
  if (!empty($module->info['required'])) {

    // Used when displaying modules that are required by the installation
    // profile.
    $row['enable']['#disabled'] = TRUE;
    $row['#required_by'][] = $distribution . (!empty($module->info['explanation']) ? ' (' . $module->info['explanation'] . ')' : '');
  }

  // Check the compatibilities.
  $compatible = TRUE;

  // Initialize an empty array of reasons why the module is incompatible. Add
  // each reason as a separate element of the array.
  $reasons = [];

  // Check the core compatibility.
  if ($module->info['core'] != \Drupal::CORE_COMPATIBILITY) {
    $compatible = FALSE;
    $reasons[] = $this
      ->t('This version is not compatible with Drupal
        @core_version and should be replaced.', [
      '@core_version' => \Drupal::CORE_COMPATIBILITY,
    ]);
  }

  // Ensure this module is compatible with the currently installed version
  // of PHP.
  if (version_compare(phpversion(), $module->info['php']) < 0) {
    $compatible = FALSE;
    $required = $module->info['php'] . (substr_count($module->info['php'], '.') < 2 ? '.*' : '');
    $reasons[] = $this
      ->t('This module requires PHP version @php_required and
        is incompatible with PHP version @php_version.', [
      '@php_required' => $required,
      '@php_version' => phpversion(),
    ]);
  }

  // If this module is not compatible, disable the checkbox.
  if (!$compatible) {
    $status = implode(' ', $reasons);
    $row['enable']['#disabled'] = TRUE;
    $row['description']['#markup'] = $status;
    $row['#attributes']['class'][] = 'incompatible';
  }

  // If this module requires other modules, add them to the array.
  foreach ($module->requires as $dependency => $version) {
    if (!isset($modules[$dependency])) {
      $row['#requires'][$dependency] = $this
        ->t('@module (<span class="admin-missing">missing</span>)', [
        '@module' => Unicode::ucfirst($dependency),
      ]);
      $row['enable']['#disabled'] = TRUE;
    }
    elseif (empty($modules[$dependency]->hidden)) {
      $name = $modules[$dependency]->info['name'];

      // Disable the module's checkbox if it is incompatible with the
      // dependency's version.
      if ($incompatible_version = drupal_check_incompatibility($version, str_replace(\Drupal::CORE_COMPATIBILITY . '-', '', $modules[$dependency]->info['version']))) {
        $row['#requires'][$dependency] = $this
          ->t('@module (<span class="admin-missing">incompatible with</span> version @version)', [
          '@module' => $name . $incompatible_version,
          '@version' => $modules[$dependency]->info['version'],
        ]);
        $row['enable']['#disabled'] = TRUE;
      }
      elseif ($modules[$dependency]->info['core'] != \Drupal::CORE_COMPATIBILITY) {
        $row['#requires'][$dependency] = $this
          ->t('@module (<span class="admin-missing">incompatible with</span> this version of Drupal core)', [
          '@module' => $name,
        ]);
        $row['enable']['#disabled'] = TRUE;
      }
      elseif ($modules[$dependency]->status) {
        $row['#requires'][$dependency] = $this
          ->t('@module', [
          '@module' => $name,
        ]);
      }
      else {
        $row['#requires'][$dependency] = $this
          ->t('@module (<span class="admin-disabled">disabled</span>)', [
          '@module' => $name,
        ]);
      }
    }
  }

  // If this module is required by other modules, list those, and then make it
  // impossible to disable this one.
  foreach ($module->required_by as $dependent => $version) {
    if (isset($modules[$dependent]) && empty($modules[$dependent]->info['hidden'])) {
      if ($modules[$dependent]->status == 1 && $module->status == 1) {
        $row['#required_by'][$dependent] = $this
          ->t('@module', [
          '@module' => $modules[$dependent]->info['name'],
        ]);
        $row['enable']['#disabled'] = TRUE;
      }
      else {
        $row['#required_by'][$dependent] = $this
          ->t('@module (<span class="admin-disabled">disabled</span>)', [
          '@module' => $modules[$dependent]->info['name'],
        ]);
      }
    }
  }
  return $row;
}