You are here

public function UpgradeStatusForm::buildForm in Upgrade Status 8

Same name and namespace in other branches
  1. 8.3 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 104

Class

UpgradeStatusForm

Namespace

Drupal\upgrade_status\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['#attached']['library'][] = 'upgrade_status/upgrade_status.admin';

  // 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',
  ];
  $form['drupal_upgrade_status_form']['action']['export'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Export as HTML'),
    '#weight' => 5,
    '#submit' => [
      [
        $this,
        'exportReportHTML',
      ],
    ],
  ];
  $form['drupal_upgrade_status_form']['action']['export_ascii'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Export as ASCII'),
    '#weight' => 6,
    '#submit' => [
      [
        $this,
        'exportReportASCII',
      ],
    ],
  ];
  return $form;
}