public function ModuleConfigureForm::buildForm in Thunder 6.1.x
Same name and namespace in other branches
- 8.5 src/Installer/Form/ModuleConfigureForm.php \Drupal\thunder\Installer\Form\ModuleConfigureForm::buildForm()
- 8.2 src/Installer/Form/ModuleConfigureForm.php \Drupal\thunder\Installer\Form\ModuleConfigureForm::buildForm()
- 8.3 src/Installer/Form/ModuleConfigureForm.php \Drupal\thunder\Installer\Form\ModuleConfigureForm::buildForm()
- 8.4 src/Installer/Form/ModuleConfigureForm.php \Drupal\thunder\Installer\Form\ModuleConfigureForm::buildForm()
- 6.2.x src/Installer/Form/ModuleConfigureForm.php \Drupal\thunder\Installer\Form\ModuleConfigureForm::buildForm()
- 6.0.x src/Installer/Form/ModuleConfigureForm.php \Drupal\thunder\Installer\Form\ModuleConfigureForm::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- src/
Installer/ Form/ ModuleConfigureForm.php, line 154
Class
- ModuleConfigureForm
- Provides the site configuration form.
Namespace
Drupal\thunder\Installer\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['description'] = [
'#type' => 'item',
'#markup' => $this
->t('This is a list of modules that are supported by Thunder, but not enabled by default.'),
];
$form['install_modules'] = [
'#type' => 'container',
'#tree' => TRUE,
];
$modules = $this->moduleExtensionList
->getList();
$thunder_features = array_filter($modules, function (Extension $module) {
return $module->info['package'] === 'Thunder Optional';
});
foreach ($thunder_features as $id => $module) {
$form['install_modules'][$id] = [
'#type' => 'container',
];
$form['install_modules'][$id]['enable'] = [
'#type' => 'checkbox',
'#title' => $module->info['name'],
'#default_value' => $module->status,
'#disabled' => $module->status,
];
$form['install_modules'][$id]['info'] = [
'#type' => 'container',
'#attributes' => [
'class' => [
'module-info',
],
],
];
$form['install_modules'][$id]['info']['description'] = [
'#markup' => '<span class="text module-description">' . $module->info['description'] . '</span>',
];
$requires = [];
// 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)) {
$requires[$dependency] = $incompatible;
$form['install_modules'][$id]['enable']['#disabled'] = TRUE;
continue;
}
$name = $modules[$dependency]->info['name'];
$requires[$dependency] = $modules[$dependency]->status ? $this
->t('@module', [
'@module' => $name,
]) : $this
->t('@module (<span class="admin-disabled">disabled</span>)', [
'@module' => $name,
]);
}
$form['install_modules'][$id]['info']['requires'] = [
'#prefix' => '<div class="admin-requirements">Requires: ',
'#suffix' => '</div>',
'#theme' => 'item_list',
'#items' => $requires,
'#context' => [
'list_style' => 'comma-list',
],
];
if ($module->status) {
// 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') && in_array($module
->getName(), $this->moduleHandler
->getImplementations('help'))) {
$form['install_modules'][$id]['info']['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 ($this->currentUser
->hasPermission('administer permissions') && $this->permissionHandler
->moduleProvidesPermissions($module
->getName())) {
$form['install_modules'][$id]['info']['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 (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)) {
$form['install_modules'][$id]['info']['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',
],
],
],
];
}
}
}
}
$form['#title'] = $this
->t('Install & configure modules');
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['save'] = [
'#type' => 'submit',
'#value' => $this
->t('Save and continue'),
'#button_type' => 'primary',
];
$form['#attached']['library'][] = 'thunder/module.configure.form';
return $form;
}