You are here

protected function UpgradeStatusForm::buildProjectList in Upgrade Status 8.3

Same name and namespace in other branches
  1. 8 src/Form/UpgradeStatusForm.php \Drupal\upgrade_status\Form\UpgradeStatusForm::buildProjectList()
  2. 8.2 src/Form/UpgradeStatusForm.php \Drupal\upgrade_status\Form\UpgradeStatusForm::buildProjectList()

Builds a list and status summary of projects.

Parameters

\Drupal\Core\Extension\Extension[] $projects: Array of extensions representing projects.

string $next_step: The machine name of the suggested next step to take for these projects.

Return value

array Build array.

1 call to UpgradeStatusForm::buildProjectList()
UpgradeStatusForm::buildForm in src/Form/UpgradeStatusForm.php
Form constructor.

File

src/Form/UpgradeStatusForm.php, line 305

Class

UpgradeStatusForm

Namespace

Drupal\upgrade_status\Form

Code

protected function buildProjectList(array $projects, string $next_step) {
  $header = [
    'project' => [
      'data' => $this
        ->t('Project'),
      'class' => 'project-label',
    ],
    'type' => [
      'data' => $this
        ->t('Type'),
      'class' => 'type-label',
    ],
    'status' => [
      'data' => $this
        ->t('Status'),
      'class' => 'status-label',
    ],
    'version' => [
      'data' => $this
        ->t('Local version'),
      'class' => 'version-label',
    ],
    'ready' => [
      'data' => $this
        ->t('Local ' . $this->nextMajor . '-ready'),
      'class' => 'ready-label',
    ],
    'result' => [
      'data' => $this
        ->t('Local scan result'),
      'class' => 'scan-info',
    ],
    'updatev' => [
      'data' => $this
        ->t('Drupal.org version'),
      'class' => 'updatev-info',
    ],
    'update9' => [
      'data' => $this
        ->t('Drupal.org ' . $this->nextMajor . '-ready'),
      'class' => 'update9-info',
    ],
    'issues' => [
      'data' => $this
        ->t('Drupal.org issues'),
      'class' => 'issue-info',
    ],
    'plan' => [
      'data' => $this
        ->t('Plan'),
      'class' => 'plan-info',
    ],
  ];
  $build['list'] = [
    '#type' => 'tableselect',
    '#header' => $header,
    '#weight' => 20,
    '#options' => [],
  ];
  foreach ($projects as $name => $extension) {
    $option = [
      '#attributes' => [
        'class' => 'project-' . $name,
      ],
    ];
    $option['project'] = [
      'data' => [
        'label' => [
          '#type' => 'html_tag',
          '#tag' => 'label',
          '#value' => $extension->info['name'],
          '#attributes' => [
            'for' => 'edit-' . $next_step . '-data-list-' . str_replace('_', '-', $name),
          ],
        ],
      ],
      'class' => 'project-label',
    ];
    $option['type'] = [
      'data' => [
        'label' => [
          '#type' => 'markup',
          '#markup' => $extension->info['upgrade_status_type'] == ProjectCollector::TYPE_CUSTOM ? $this
            ->t('Custom') : $this
            ->t('Contributed'),
        ],
      ],
    ];
    $option['status'] = [
      'data' => [
        'label' => [
          '#type' => 'markup',
          '#markup' => empty($extension->status) ? $this
            ->t('Uninstalled') : $this
            ->t('Installed'),
        ],
      ],
    ];

    // Start of local version/readiness columns.
    $option['version'] = [
      'data' => [
        'label' => [
          '#type' => 'markup',
          '#markup' => !empty($extension->info['version']) ? $extension->info['version'] : $this
            ->t('N/A'),
        ],
      ],
    ];
    $option['ready'] = [
      'class' => 'status-info ' . (!empty($extension->info['upgrade_status_next_major_compatible']) ? 'status-info-compatible' : 'status-info-incompatible'),
      'data' => [
        'label' => [
          '#type' => 'markup',
          '#markup' => !empty($extension->info['upgrade_status_next_major_compatible']) ? $this
            ->t('Compatible') : $this
            ->t('Incompatible'),
        ],
      ],
    ];
    $report = $this->projectCollector
      ->getResults($name);
    $result_summary = !empty($report) ? $this
      ->t('No problems found') : $this
      ->t('N/A');
    if (!empty($report['data']['totals']['file_errors'])) {
      $result_summary = $this
        ->formatPlural($report['data']['totals']['file_errors'], '@count problem', '@count problems');
      $option['result'] = [
        'data' => [
          '#type' => 'link',
          '#title' => $result_summary,
          '#url' => Url::fromRoute('upgrade_status.project', [
            'project_machine_name' => $name,
          ]),
          '#attributes' => [
            'class' => [
              'use-ajax',
            ],
            'data-dialog-type' => 'modal',
            'data-dialog-options' => Json::encode([
              'width' => 1024,
              'height' => 568,
            ]),
          ],
        ],
        'class' => 'scan-result',
      ];
    }
    else {
      $option['result'] = [
        'data' => [
          'label' => [
            '#type' => 'markup',
            '#markup' => $result_summary,
          ],
        ],
        'class' => 'scan-result',
      ];
    }

    // Start of drupal.org data columns.
    $updatev = $this
      ->t('Not applicable');
    if (!empty($extension->info['upgrade_status_update_link'])) {
      $option['updatev'] = [
        'data' => [
          'link' => [
            '#type' => 'link',
            '#title' => $extension->info['upgrade_status_update_version'],
            '#url' => Url::fromUri($extension->info['upgrade_status_update_link']),
          ],
        ],
      ];
      unset($updatev);
    }
    elseif (!empty($extension->info['upgrade_status_update'])) {
      $updatev = $this
        ->t('Unavailable');
      if ($extension->info['upgrade_status_update'] == ProjectCollector::UPDATE_NOT_CHECKED) {
        $updatev = $this
          ->t('Unchecked');
      }
      elseif ($extension->info['upgrade_status_update'] == ProjectCollector::UPDATE_ALREADY_INSTALLED) {
        $updatev = $this
          ->t('Up to date');
      }
    }
    if (!empty($updatev)) {
      $option['updatev'] = [
        'data' => [
          'label' => [
            '#type' => 'markup',
            '#markup' => $updatev,
          ],
        ],
      ];
    }
    $update_class = 'status-info-na';
    $update_info = $this
      ->t('Not applicable');
    if (isset($extension->info['upgrade_status_update'])) {
      switch ($extension->info['upgrade_status_update']) {
        case ProjectCollector::UPDATE_NOT_AVAILABLE:
          $update_info = $this
            ->t('Unavailable');
          $update_class = 'status-info-na';
          break;
        case ProjectCollector::UPDATE_NOT_CHECKED:
          $update_info = $this
            ->t('Unchecked');
          $update_class = 'status-info-unchecked';
          break;
        case ProjectCollector::UPDATE_AVAILABLE:
        case ProjectCollector::UPDATE_ALREADY_INSTALLED:
          if ($extension->info['upgrade_status_update_compatible']) {
            $update_info = $this
              ->t('Compatible');
            $update_class = 'status-info-compatible';
          }
          else {
            $update_info = $this
              ->t('Incompatible');
            $update_class = 'status-info-incompatible';
          }
          break;
      }
    }
    $option['update9'] = [
      'class' => 'status-info ' . $update_class,
      'data' => [
        'label' => [
          '#type' => 'markup',
          '#markup' => $update_info,
        ],
      ],
    ];
    if ($extension->info['upgrade_status_type'] == ProjectCollector::TYPE_CUSTOM) {
      $option['issues'] = $option['plan'] = [
        'data' => [
          'label' => [
            '#type' => 'markup',
            '#markup' => $this
              ->t('Not applicable'),
          ],
        ],
      ];
    }
    else {
      $plan = (string) $this->projectCollector
        ->getPlan($name);
      $option['issues'] = [
        'data' => [
          'label' => [
            '#type' => 'markup',
            // Use the project name from the info array instead of $key.
            // $key is the local name, not necessarily the project name.
            '#markup' => '<a href="https://drupal.org/project/issues/' . $extension->info['project'] . '?text=Drupal+' . $this->nextMajor . '&status=All">' . $this
              ->t('Issues', [], [
              'context' => 'Drupal.org issues',
            ]) . '</a>',
          ],
        ],
      ];
      $plan = (string) $this->projectCollector
        ->getPlan($name);
      $option['plan'] = [
        'data' => [
          'label' => [
            '#type' => 'markup',
            '#markup' => !empty($plan) ? $plan : $this
              ->t('N/A'),
          ],
        ],
      ];
    }
    $build['list']['#options'][$name] = $option;
  }
  return $build;
}