Skip to content
Snippets Groups Projects

Issue #3264849: Show next minor or current minor updates in Update form

1 file
+ 58
38
Compare changes
  • Side-by-side
  • Inline
+ 58
38
@@ -8,6 +8,7 @@ use Drupal\automatic_updates\ProjectInfo;
use Drupal\automatic_updates\ReleaseChooser;
use Drupal\automatic_updates\Updater;
use Drupal\automatic_updates\Validation\ReadinessTrait;
use Drupal\automatic_updates_9_3_shim\ProjectRelease;
use Drupal\Core\Batch\BatchBuilder;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
@@ -154,10 +155,8 @@ class UpdaterForm extends FormBase {
// one release on the form. First, try to show the latest release in the
// currently installed minor. Failing that, try to show the latest
// release in the next minor.
$recommended_release = $this->releaseChooser->getLatestInInstalledMinor($this->updater);
if (!$recommended_release) {
$recommended_release = $this->releaseChooser->getLatestInNextMinor($this->updater);
}
$installed_minor_release = $this->releaseChooser->getLatestInInstalledMinor($this->updater);
$next_minor_release = $this->releaseChooser->getLatestInNextMinor($this->updater);
}
catch (\RuntimeException $e) {
$form['message'] = [
@@ -170,7 +169,7 @@ class UpdaterForm extends FormBase {
$form['#attached']['library'][] = 'update/drupal.update.admin';
$project = $project_info->getProjectInfo();
if ($recommended_release === NULL) {
if ($installed_minor_release === NULL && $next_minor_release === NULL) {
if ($project['status'] === UpdateManagerInterface::CURRENT) {
$this->messenger()->addMessage($this->t('No update available'));
}
@@ -189,7 +188,7 @@ class UpdaterForm extends FormBase {
$form['target_version'] = [
'#type' => 'value',
'#value' => [
'drupal' => $recommended_release->getVersion(),
'drupal' => $installed_minor_release->getVersion(),
],
];
@@ -216,26 +215,13 @@ class UpdaterForm extends FormBase {
}
// Create an entry for this project.
$entry = [
'title' => [
'data' => $title,
],
'installed_version' => $project_info->getInstalledVersion(),
'recommended_version' => [
'data' => [
// @todo Is an inline template the right tool here? Is there an Update
// module template we should use instead?
'#type' => 'inline_template',
'#template' => '{{ release_version }} (<a href="{{ release_link }}" title="{{ project_title }}">{{ release_notes }}</a>)',
'#context' => [
'release_version' => $recommended_release->getVersion(),
'release_link' => $recommended_release->getReleaseUrl(),
'project_title' => $this->t('Release notes for @project_title', ['@project_title' => $project['title']]),
'release_notes' => $this->t('Release notes'),
],
],
],
];
$rows = [];
if ($installed_minor_release) {
$rows['drupal-install-minor'] = $this->getReleaseRow($title, $project_info, $installed_minor_release, $project['title']);
}
if ($next_minor_release) {
$rows['drupal-next-minor'] = $this->getReleaseRow($title, $project_info, $next_minor_release, $project['title']);
}
$form['projects'] = [
'#type' => 'table',
@@ -246,15 +232,11 @@ class UpdaterForm extends FormBase {
],
'installed_version' => $this->t('Installed version'),
'recommended_version' => [
'data' => $this->t('Recommended version'),
],
],
'#rows' => [
'drupal' => [
'class' => "update-$type",
'data' => $entry,
'data' => $this->t('Update version'),
],
'submit' => $this->t('Update'),
],
'#rows' => $rows,
];
if ($form_state->getUserInput()) {
@@ -262,7 +244,7 @@ class UpdaterForm extends FormBase {
}
else {
$event = new ReadinessCheckEvent($this->updater, [
'drupal' => $recommended_release->getVersion(),
'drupal' => $installed_minor_release->getVersion(),
]);
$this->eventDispatcher->dispatch($event);
$results = $event->getResults();
@@ -284,10 +266,7 @@ class UpdaterForm extends FormBase {
}
// If there were no errors, allow the user to proceed with the update.
elseif ($this->getOverallSeverity($results) !== SystemManager::REQUIREMENT_ERROR) {
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Update'),
];
}
$form['actions']['#type'] = 'actions';
@@ -311,6 +290,7 @@ class UpdaterForm extends FormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state->getTriggeringElement();
$batch = (new BatchBuilder())
->setTitle($this->t('Downloading updates'))
->setInitMessage($this->t('Preparing to download updates'))
@@ -341,4 +321,44 @@ class UpdaterForm extends FormBase {
return $this->traitFormatResult($result);
}
/**
* @param array $title
* @param \Drupal\automatic_updates\ProjectInfo $project_info
* @param \Drupal\automatic_updates_9_3_shim\ProjectRelease $recommended_release
* @param $title1
*
* @return array
*/
protected function getReleaseRow(array $title, ProjectInfo $project_info, ProjectRelease $recommended_release, $title1): array {
$entry = [
'title' => [
'data' => $title,
],
'installed_version' => $project_info->getInstalledVersion(),
'recommended_version' => [
'data' => [
// @todo Is an inline template the right tool here? Is there an Update
// module template we should use instead?
'#type' => 'inline_template',
'#template' => '{{ release_version }} (<a href="{{ release_link }}" title="{{ project_title }}">{{ release_notes }}</a>)',
'#context' => [
'release_version' => $recommended_release->getVersion(),
'release_link' => $recommended_release->getReleaseUrl(),
'project_title' => $this->t('Release notes for @project_title', ['@project_title' => $title1]),
'release_notes' => $this->t('Release notes'),
],
],
],
'submit' => [
'#type' => 'button',
'#value' => $this->t('Update to @version', ['@version' => $recommended_release->getVersion()]),
'#executes_submit_callback' => TRUE,
],
];
return [
//'class' => "update-$type",
'data' => $entry,
];
}
}
Loading