/**
  * {@inheritdoc}
  */
 public function buildForm(array $form, array &$form_state)
 {
     // Retrieve the list of modules from the key value store.
     $account = $this->currentUser()->id();
     $this->modules = $this->keyValueExpirable->get($account);
     // Prevent this page from showing when the module list is empty.
     if (empty($this->modules)) {
         return new RedirectResponse('/admin/modules/uninstall');
     }
     $data = system_rebuild_module_data();
     $form['text']['#markup'] = '<p>' . $this->t('The following modules will be completely uninstalled from your site, and <em>all data from these modules will be lost</em>!') . '</p>';
     $form['modules'] = array('#theme' => 'item_list', '#items' => array_map(function ($module) use($data) {
         return $data[$module]->info['name'];
     }, $this->modules));
     $form['entities'] = array('#type' => 'details', '#title' => $this->t('Configuration deletions'), '#description' => $this->t('The listed configuration will be deleted.'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#access' => FALSE);
     // Get the dependent entities.
     $entity_types = array();
     $dependent_entities = $this->configManager->findConfigEntityDependentsAsEntities('module', $this->modules);
     foreach ($dependent_entities as $entity) {
         $entity_type_id = $entity->getEntityTypeId();
         if (!isset($form['entities'][$entity_type_id])) {
             $entity_type = $this->entityManager->getDefinition($entity_type_id);
             // Store the ID and label to sort the entity types and entities later.
             $label = $entity_type->getLabel();
             $entity_types[$entity_type_id] = $label;
             $form['entities'][$entity_type_id] = array('#theme' => 'item_list', '#title' => $label, '#items' => array());
         }
         $form['entities'][$entity_type_id]['#items'][] = $entity->label();
     }
     if (!empty($dependent_entities)) {
         $form['entities']['#access'] = TRUE;
         // Add a weight key to the entity type sections.
         asort($entity_types, SORT_FLAG_CASE);
         $weight = 0;
         foreach ($entity_types as $entity_type_id => $label) {
             $form['entities'][$entity_type_id]['#weight'] = $weight;
             // Sort the list of entity labels alphabetically.
             sort($form['entities'][$entity_type_id]['#items'], SORT_FLAG_CASE);
             $weight++;
         }
     }
     return parent::buildForm($form, $form_state);
 }