public ModulesUninstallForm::buildForm(array $form, FormStateInterface $form_state)
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
- core/modules/system/src/Form/ModulesUninstallForm.php, line 75
Class
- ModulesUninstallForm
- Provides a form for uninstalling modules.
Namespace
Drupal\system\Form
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | public function buildForm( array $form , FormStateInterface $form_state ) { // Make sure the install API is available. include_once DRUPAL_ROOT . '/core/includes/install.inc' ; // Get a list of all available modules. $modules = system_rebuild_module_data(); $uninstallable = array_filter ( $modules , function ( $module ) use ( $modules ) { return empty ( $modules [ $module ->getName()]->info[ 'required' ]) && $module ->status; }); // Include system.admin.inc so we can use the sort callbacks. $this ->moduleHandler->loadInclude( 'system' , 'inc' , 'system.admin' ); $form [ 'filters' ] = array ( '#type' => 'container' , '#attributes' => array ( 'class' => array ( 'table-filter' , 'js-show' ), ), ); $form [ 'filters' ][ 'text' ] = array ( '#type' => 'search' , '#title' => $this ->t( 'Filter modules' ), '#title_display' => 'invisible' , '#size' => 30, '#placeholder' => $this ->t( 'Filter by name or description' ), '#description' => $this ->t( 'Enter a part of the module name or description' ), '#attributes' => array ( 'class' => array ( 'table-filter-text' ), 'data-table' => '#system-modules-uninstall' , 'autocomplete' => 'off' , ), ); $form [ 'modules' ] = array (); // Only build the rest of the form if there are any modules available to // uninstall; if ( empty ( $uninstallable )) { return $form ; } $profile = drupal_get_profile(); // Sort all modules by their name. uasort( $uninstallable , 'system_sort_modules_by_info_name' ); $validation_reasons = $this ->moduleInstaller->validateUninstall( array_keys ( $uninstallable )); $form [ 'uninstall' ] = array ( '#tree' => TRUE); foreach ( $uninstallable as $module_key => $module ) { $name = $module ->info[ 'name' ] ? : $module ->getName(); $form [ 'modules' ][ $module ->getName()][ '#module_name' ] = $name ; $form [ 'modules' ][ $module ->getName()][ 'name' ][ '#markup' ] = $name ; $form [ 'modules' ][ $module ->getName()][ 'description' ][ '#markup' ] = $this ->t( $module ->info[ 'description' ]); $form [ 'uninstall' ][ $module ->getName()] = array ( '#type' => 'checkbox' , '#title' => $this ->t( 'Uninstall @module module' , array ( '@module' => $name )), '#title_display' => 'invisible' , ); // If a validator returns reasons not to uninstall a module, // list the reasons and disable the check box. if (isset( $validation_reasons [ $module_key ])) { $form [ 'modules' ][ $module ->getName()][ '#validation_reasons' ] = $validation_reasons [ $module_key ]; $form [ 'uninstall' ][ $module ->getName()][ '#disabled' ] = TRUE; } // All modules which depend on this one must be uninstalled first, before // we can allow this module to be uninstalled. (The installation profile // is excluded from this list.) foreach ( array_keys ( $module ->required_by) as $dependent ) { if ( $dependent != $profile && drupal_get_installed_schema_version( $dependent ) != SCHEMA_UNINSTALLED) { $name = isset( $modules [ $dependent ]->info[ 'name' ]) ? $modules [ $dependent ]->info[ 'name' ] : $dependent ; $form [ 'modules' ][ $module ->getName()][ '#required_by' ][] = $name ; $form [ 'uninstall' ][ $module ->getName()][ '#disabled' ] = TRUE; } } } $form [ '#attached' ][ 'library' ][] = 'system/drupal.system.modules' ; $form [ 'actions' ] = array ( '#type' => 'actions' ); $form [ 'actions' ][ 'submit' ] = array ( '#type' => 'submit' , '#value' => $this ->t( 'Uninstall' ), ); return $form ; } |
Please login to continue.