function DevelReinstall::buildForm
Same name in other branches
- 4.x src/Form/DevelReinstall.php \Drupal\devel\Form\DevelReinstall::buildForm()
Overrides FormInterface::buildForm
File
-
src/
Form/ DevelReinstall.php, line 55
Class
- DevelReinstall
- Display a dropdown of installed modules with the option to reinstall them.
Namespace
Drupal\devel\FormCode
public function buildForm(array $form, FormStateInterface $form_state) : array {
// Get a list of all available modules.
$modules = $this->moduleExtensionList
->reset()
->getList();
$uninstallable = array_filter($modules, fn($module): bool => empty($modules[$module->getName()]->info['required']) && $this->updateHookRegistry
->getInstalledVersion($module->getName()) > UpdateHookRegistry::SCHEMA_UNINSTALLED && $module->getName() !== 'devel');
$form['filters'] = [
'#type' => 'container',
'#attributes' => [
'class' => [
'table-filter',
'js-show',
],
],
];
$form['filters']['text'] = [
'#type' => 'search',
'#title' => $this->t('Search'),
'#size' => 30,
'#placeholder' => $this->t('Enter module name'),
'#attributes' => [
'class' => [
'table-filter-text',
],
'data-table' => '#devel-reinstall-form',
'autocomplete' => 'off',
'title' => $this->t('Enter a part of the module name or description to filter by.'),
],
];
// Only build the rest of the form if there are any modules available to
// uninstall.
if ($uninstallable === []) {
return $form;
}
$header = [
'name' => $this->t('Name'),
'description' => $this->t('Description'),
];
$rows = [];
foreach ($uninstallable as $module) {
$name = $module->info['name'] ?: $module->getName();
$rows[$module->getName()] = [
'name' => [
'data' => [
'#type' => 'inline_template',
'#template' => '<label class="module-name table-filter-text-source">{{ module_name }}</label>',
'#context' => [
'module_name' => $name,
],
],
],
'description' => [
'data' => $module->info['description'],
'class' => [
'description',
],
],
];
}
$form['reinstall'] = [
'#type' => 'tableselect',
'#header' => $header,
'#options' => $rows,
'#js_select' => FALSE,
'#empty' => $this->t('No modules are available to uninstall.'),
];
$form['#attached']['library'][] = 'system/drupal.system.modules';
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Reinstall'),
];
return $form;
}