Verified Commit b102e5e9 authored by Dave Long's avatar Dave Long
Browse files

Issue #3121870 by quietone, narendraR, smustgrave, dww: Change implementation...

Issue #3121870 by quietone, narendraR, smustgrave, dww: Change implementation details of UpdateManagerUpdateForm to use install/uninstall
parent 021e0ede
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ public function processInfoList(array &$projects, array $list, $project_type, $s
      }
      if (empty($status)) {
        // If we're processing uninstalled modules or themes, append a suffix.
        $project_display_type .= '-disabled';
        $project_display_type .= '-uninstalled';
      }
      if (!isset($projects[$project_name])) {
        // Only process this if we haven't done this project, since a single
+20 −20
Original line number Diff line number Diff line
@@ -92,14 +92,14 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    $form['#attached']['library'][] = 'update/drupal.update.admin';

    // This will be a nested array. The first key is the kind of project, which
    // can be either 'enabled', 'disabled', 'manual' (projects which require
    // manual updates, such as core). Then, each subarray is an array of
    // can be either 'installed', 'uninstalled', 'manual' (projects which
    // require manual updates, such as core). Then, each subarray is an array of
    // projects of that type, indexed by project short name, and containing an
    // array of data for cells in that project's row in the appropriate table.
    $projects = [];

    // This stores the actual download link we're going to update from for each
    // project in the form, regardless of if it's enabled or disabled.
    // project in the form, regardless of if it's installed or uninstalled.
    $form['project_downloads'] = ['#tree' => TRUE];
    $this->moduleHandler->loadInclude('update', 'inc', 'update.compare');
    $project_data = update_calculate_project_data($available);
@@ -129,7 +129,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
      else {
        $project_name = $name;
      }
      if ($project['project_type'] == 'theme' || $project['project_type'] == 'theme-disabled') {
      if ($project['project_type'] == 'theme' || $project['project_type'] == 'theme-uninstalled') {
        $project_name .= ' ' . $this->t('(Theme)');
      }

@@ -238,12 +238,12 @@ public function buildForm(array $form, FormStateInterface $form_state) {
        switch ($project['project_type']) {
          case 'module':
          case 'theme':
            $projects['enabled'][$name] = $entry;
            $projects['installed'][$name] = $entry;
            break;

          case 'module-disabled':
          case 'theme-disabled':
            $projects['disabled'][$name] = $entry;
          case 'module-uninstalled':
          case 'theme-uninstalled':
            $projects['uninstalled'][$name] = $entry;
            break;
        }
      }
@@ -270,22 +270,22 @@ public function buildForm(array $form, FormStateInterface $form_state) {
      'recommended_version' => $this->t('Recommended version'),
    ];

    if (!empty($projects['enabled'])) {
    if (!empty($projects['installed'])) {
      $form['projects'] = [
        '#type' => 'tableselect',
        '#header' => $headers,
        '#options' => $projects['enabled'],
        '#options' => $projects['installed'],
      ];
      if (!empty($projects['disabled'])) {
      if (!empty($projects['uninstalled'])) {
        $form['projects']['#prefix'] = '<h2>' . $this->t('Installed') . '</h2>';
      }
    }

    if (!empty($projects['disabled'])) {
      $form['disabled_projects'] = [
    if (!empty($projects['uninstalled'])) {
      $form['uninstalled_projects'] = [
        '#type' => 'tableselect',
        '#header' => $headers,
        '#options' => $projects['disabled'],
        '#options' => $projects['uninstalled'],
        '#weight' => 1,
        '#prefix' => '<h2>' . $this->t('Uninstalled') . '</h2>',
      ];
@@ -293,7 +293,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {

    // If either table has been printed yet, we need a submit button and to
    // validate the checkboxes.
    if (!empty($projects['enabled']) || !empty($projects['disabled'])) {
    if (!empty($projects['installed']) || !empty($projects['uninstalled'])) {
      $form['actions'] = ['#type' => 'actions'];
      $form['actions']['submit'] = [
        '#type' => 'submit',
@@ -357,12 +357,12 @@ protected function removeCheckboxFromRow(array &$row) {
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    if (!$form_state->isValueEmpty('projects')) {
      $enabled = array_filter($form_state->getValue('projects'));
      $installed = array_filter($form_state->getValue('projects'));
    }
    if (!$form_state->isValueEmpty('disabled_projects')) {
      $disabled = array_filter($form_state->getValue('disabled_projects'));
    if (!$form_state->isValueEmpty('uninstalled_projects')) {
      $uninstalled = array_filter($form_state->getValue('uninstalled_projects'));
    }
    if (empty($enabled) && empty($disabled)) {
    if (empty($installed) && empty($uninstalled)) {
      $form_state->setErrorByName('projects', $this->t('You must select at least one project to update.'));
    }
  }
@@ -373,7 +373,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->moduleHandler->loadInclude('update', 'inc', 'update.manager');
    $projects = [];
    foreach (['projects', 'disabled_projects'] as $type) {
    foreach (['projects', 'uninstalled_projects'] as $type) {
      if (!$form_state->isValueEmpty($type)) {
        $projects = array_merge($projects, array_keys(array_filter($form_state->getValue($type))));
      }
+1 −3
Original line number Diff line number Diff line
@@ -242,9 +242,7 @@ public function testIncompatibleUpdatesTable($core_fixture, $a_fixture, $b_fixtu
  public function testUninstalledUpdatesTable() {
    $assert_session = $this->assertSession();
    $compatible_table_locator = '[data-drupal-selector="edit-projects"]';
    // @todo In https://www.drupal.org/project/drupal/issues/3121870 change this
    //   selector when the implementation details catch up with the UI strings.
    $uninstalled_table_locator = '[data-drupal-selector="edit-disabled-projects"]';
    $uninstalled_table_locator = '[data-drupal-selector="edit-uninstalled-projects"]';

    $fixtures = [
      'drupal' => '1.1-core_compatibility',
+2 −2
Original line number Diff line number Diff line
@@ -88,8 +88,8 @@ function template_preprocess_update_report(&$variables) {
    'core' => t('Drupal core'),
    'module' => t('Modules'),
    'theme' => t('Themes'),
    'module-disabled' => t('Uninstalled modules'),
    'theme-disabled' => t('Uninstalled themes'),
    'module-uninstalled' => t('Uninstalled modules'),
    'theme-uninstalled' => t('Uninstalled themes'),
  ];

  $variables['project_types'] = [];