You are here

public function UpgradeStatusForm::buildForm in Upgrade Status 8.2

Same name and namespace in other branches
  1. 8.3 src/Form/UpgradeStatusForm.php \Drupal\upgrade_status\Form\UpgradeStatusForm::buildForm()
  2. 8 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 181

Class

UpgradeStatusForm

Namespace

Drupal\upgrade_status\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['#attached']['library'][] = 'upgrade_status/upgrade_status.admin';
  $analyzerReady = TRUE;
  try {
    $this->deprecationAnalyzer
      ->initEnvironment();
  } catch (\Exception $e) {
    $analyzerReady = FALSE;
    $this
      ->messenger()
      ->addError($e
      ->getMessage());
  }
  $last = $this->state
    ->get('update.last_check') ?: 0;
  if ($last == 0) {
    $last_checked = '<strong>' . $this
      ->t('Available update data not available.') . '</strong>';
  }
  else {
    $time = $this->dateFormatter
      ->formatTimeDiffSince($last);
    $last_checked = $this
      ->t('Available update data last checked: @time ago.', [
      '@time' => $time,
    ]);
  }
  $form['update_time'] = [
    [
      '#type' => 'markup',
      '#markup' => $last_checked . ' ',
    ],
    [
      '#type' => 'link',
      '#title' => '(' . $this
        ->t('Check manually') . ')',
      '#url' => Url::fromRoute('update.manual_status', [], [
        'query' => $this->destination
          ->getAsArray(),
      ]),
    ],
  ];
  $form['environment'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Drupal core and hosting environment'),
    '#description' => $this
      ->t('<a href=":upgrade">Upgrades to Drupal 9 are supported from Drupal 8.8.x and Drupal 8.9.x</a>. It is suggested to update to the latest Drupal 8 version available. <a href=":platform">Several hosting platform requirements have been raised for Drupal 9</a>.', [
      ':upgrade' => 'https://www.drupal.org/docs/9/how-to-prepare-your-drupal-7-or-8-site-for-drupal-9/upgrading-a-drupal-8-site-to-drupal-9',
      ':platform' => 'https://www.drupal.org/docs/9/how-drupal-9-is-made-and-what-is-included/environment-requirements-of-drupal-9',
    ]),
    '#open' => TRUE,
    '#attributes' => [
      'class' => [
        'upgrade-status-summary upgrade-status-summary-environment',
      ],
    ],
    'data' => $this
      ->buildEnvironmentChecks(),
    '#tree' => TRUE,
  ];

  // Gather project list grouped by custom and contrib projects.
  $projects = $this->projectCollector
    ->collectProjects();

  // List custom project status first.
  $custom = [
    '#type' => 'markup',
    '#markup' => '<br /><strong>' . $this
      ->t('No custom projects found.') . '</strong>',
  ];
  if (count($projects['custom'])) {
    $custom = $this
      ->buildProjectList($projects['custom']);
  }
  $form['custom'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Custom projects'),
    '#description' => $this
      ->t('Custom code is specific to your site, and must be upgraded manually. <a href=":upgrade">Read more about how developers can upgrade their code to Drupal 9</a>.', [
      ':upgrade' => 'https://www.drupal.org/docs/9/how-drupal-9-is-made-and-what-is-included/how-and-why-we-deprecate-on-the-way-to-drupal-9',
    ]),
    '#open' => TRUE,
    '#attributes' => [
      'class' => [
        'upgrade-status-summary upgrade-status-summary-custom',
      ],
    ],
    'data' => $custom,
    '#tree' => TRUE,
  ];

  // List contrib project status second.
  $contrib = [
    '#type' => 'markup',
    '#markup' => '<br /><strong>' . $this
      ->t('No contributed projects found.') . '</strong>',
  ];
  if (count($projects['contrib'])) {
    $contrib = $this
      ->buildProjectList($projects['contrib'], TRUE);
  }
  $form['contrib'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Contributed projects'),
    '#description' => $this
      ->t('Contributed code is available from drupal.org. Problems here may be partially resolved by updating to the latest version. <a href=":update">Read more about how to update contributed projects</a>.', [
      ':update' => 'https://www.drupal.org/docs/8/update/update-modules',
    ]),
    '#open' => TRUE,
    '#attributes' => [
      'class' => [
        'upgrade-status-summary upgrade-status-summary-contrib',
      ],
    ],
    'data' => $contrib,
    '#tree' => TRUE,
  ];
  $form['drupal_upgrade_status_form']['action']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Scan selected'),
    '#weight' => 2,
    '#button_type' => 'primary',
    '#disabled' => !$analyzerReady,
  ];
  $form['drupal_upgrade_status_form']['action']['export'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Export selected as HTML'),
    '#weight' => 5,
    '#submit' => [
      [
        $this,
        'exportReportHTML',
      ],
    ],
    '#disabled' => !$analyzerReady,
  ];
  $form['drupal_upgrade_status_form']['action']['export_ascii'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Export selected as text'),
    '#weight' => 6,
    '#submit' => [
      [
        $this,
        'exportReportASCII',
      ],
    ],
    '#disabled' => !$analyzerReady,
  ];
  return $form;
}