public ModulesListForm::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/ModulesListForm.php, line 115
Class
- ModulesListForm
- Provides module installation interface.
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 | public function buildForm( array $form , FormStateInterface $form_state ) { require_once DRUPAL_ROOT . '/core/includes/install.inc' ; $distribution = drupal_install_profile_distribution_name(); // 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' , 'autocomplete' => 'off' , ), ); // Sort all modules by their names. $modules = system_rebuild_module_data(); uasort( $modules , 'system_sort_modules_by_info_name' ); // Iterate over each of the modules. $form [ 'modules' ][ '#tree' ] = TRUE; foreach ( $modules as $filename => $module ) { if ( empty ( $module ->info[ 'hidden' ])) { $package = $module ->info[ 'package' ]; $form [ 'modules' ][ $package ][ $filename ] = $this ->buildRow( $modules , $module , $distribution ); } } // Add a wrapper around every package. foreach (Element::children( $form [ 'modules' ]) as $package ) { $form [ 'modules' ][ $package ] += array ( '#type' => 'details' , '#title' => $this ->t( $package ), '#open' => TRUE, '#theme' => 'system_modules_details' , '#attributes' => array ( 'class' => array ( 'package-listing' )), // Ensure that the "Core" package comes first. '#weight' => $package == 'Core' ? -10 : NULL, ); } // If testing modules are shown, collapse the corresponding package by // default. if (isset( $form [ 'modules' ][ 'Testing' ])) { $form [ 'modules' ][ 'Testing' ][ '#open' ] = FALSE; } // Lastly, sort all packages by title. uasort( $form [ 'modules' ], array ( '\Drupal\Component\Utility\SortArray' , 'sortByTitleProperty' )); $form [ '#attached' ][ 'library' ][] = 'system/drupal.system.modules' ; $form [ 'actions' ] = array ( '#type' => 'actions' ); $form [ 'actions' ][ 'submit' ] = array ( '#type' => 'submit' , '#value' => $this ->t( 'Install' ), '#button_type' => 'primary' , ); return $form ; } |
Please login to continue.