You are here

public function UpgradeStatusForm::buildForm in Upgrade Status 8.3

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

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

src/Form/UpgradeStatusForm.php, line 218

Class

UpgradeStatusForm

Namespace

Drupal\upgrade_status\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['#attached']['library'][] = 'upgrade_status/upgrade_status.admin';
  $analyzer_ready = TRUE;
  try {
    $this->deprecationAnalyzer
      ->initEnvironment();
  } catch (\Exception $e) {
    $analyzer_ready = FALSE;
    $this
      ->messenger()
      ->addError($e
      ->getMessage());
  }
  $environment = $this
    ->buildEnvironmentChecks();
  $form['summary'] = $this
    ->buildResultSummary($environment['status']);
  $environment_description = $environment['description'];
  unset($environment['status']);
  unset($environment['description']);
  $form['environment'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Drupal core and hosting environment'),
    '#description' => $environment_description,
    '#open' => TRUE,
    '#attributes' => [
      'class' => [
        'upgrade-status-summary-environment',
      ],
    ],
    'data' => $environment,
    '#tree' => TRUE,
  ];

  // Gather project list with metadata.
  $projects = $this->projectCollector
    ->collectProjects();
  $next_steps = $this->projectCollector
    ->getNextStepInfo();
  foreach ($next_steps as $next_step => $step_label) {
    $sublist = [];
    foreach ($projects as $name => $project) {
      if ($project->info['upgrade_status_next'] == $next_step) {
        $sublist[$name] = $project;
      }
    }
    if (!empty($sublist)) {
      $form[$next_step] = [
        '#type' => 'details',
        '#title' => $step_label[0],
        '#description' => $step_label[1],
        '#open' => TRUE,
        '#attributes' => [
          'class' => [
            'upgrade-status-summary',
            'upgrade-status-next-step-' . $next_step,
          ],
        ],
        'data' => $this
          ->buildProjectList($sublist, $next_step),
        '#tree' => TRUE,
      ];
    }
  }
  $form['drupal_upgrade_status_form']['action']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Scan selected'),
    '#weight' => 2,
    '#button_type' => 'primary',
    '#disabled' => !$analyzer_ready,
  ];
  $form['drupal_upgrade_status_form']['action']['export'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Export selected as HTML'),
    '#weight' => 5,
    '#submit' => [
      [
        $this,
        'exportReport',
      ],
    ],
    '#disabled' => !$analyzer_ready,
  ];
  $form['drupal_upgrade_status_form']['action']['export_ascii'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Export selected as text'),
    '#weight' => 6,
    '#submit' => [
      [
        $this,
        'exportReportASCII',
      ],
    ],
    '#disabled' => !$analyzer_ready,
  ];
  return $form;
}