function ModulesListForm::buildRow

Same name in other branches
  1. 9 core/modules/system/src/Form/ModulesListForm.php \Drupal\system\Form\ModulesListForm::buildRow()
  2. 10 core/modules/system/src/Form/ModulesListForm.php \Drupal\system\Form\ModulesListForm::buildRow()
  3. 11.x core/modules/system/src/Form/ModulesListForm.php \Drupal\system\Form\ModulesListForm::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.

$distribution:

Return value

array The form row for the given module.

1 call to ModulesListForm::buildRow()
ModulesListForm::buildForm in core/modules/system/src/Form/ModulesListForm.php
Form constructor.

File

core/modules/system/src/Form/ModulesListForm.php, line 228

Class

ModulesListForm
Provides module installation interface.

Namespace

Drupal\system\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($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_incompatible']) {
        $compatible = FALSE;
        $reasons[] = $this->t('This version is not compatible with Drupal @core_version and should be replaced.', [
            '@core_version' => \Drupal::VERSION,
        ]);
        $row['#requires']['core'] = $this->t('Drupal Core (@core_requirement) (<span class="admin-missing">incompatible with</span> version @core_version)', [
            '@core_requirement' => isset($module->info['core_version_requirement']) ? $module->info['core_version_requirement'] : $module->info['core'],
            '@core_version' => \Drupal::VERSION,
        ]);
    }
    // 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.
    
    /** @var \Drupal\Core\Extension\Dependency $dependency_object */
    foreach ($module->requires as $dependency => $dependency_object) {
        // @todo Add logic for not displaying hidden modules in
        //   https://drupal.org/node/3117829.
        if ($incompatible = $this->checkDependencyMessage($modules, $dependency, $dependency_object)) {
            $row['#requires'][$dependency] = $incompatible;
            $row['enable']['#disabled'] = TRUE;
            continue;
        }
        $name = $modules[$dependency]->info['name'];
        $row['#requires'][$dependency] = $modules[$dependency]->status ? $this->t('@module', [
            '@module' => $name,
        ]) : $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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.