diff --git a/core/modules/update/src/ProjectCoreCompatibility.php b/core/modules/update/src/ProjectCoreCompatibility.php
index 4aae45f91fb5..2b74248fe7a0 100644
--- a/core/modules/update/src/ProjectCoreCompatibility.php
+++ b/core/modules/update/src/ProjectCoreCompatibility.php
@@ -7,12 +7,19 @@ use Composer\Semver\VersionParser;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
- * Utility class to set core compatibility messages for module updates.
+ * Utility class to set core compatibility messages for project releases.
*/
class ProjectCoreCompatibility {
use StringTranslationTrait;
+ /**
+ * The currently installed version of Drupal core.
+ *
+ * @var string
+ */
+ protected $existingCoreVersion;
+
/**
* Cache of core versions that are available for updates.
*
@@ -50,30 +57,29 @@ class ProjectCoreCompatibility {
*/
public function __construct(array $core_data, array $core_releases) {
if (isset($core_data['existing_version'])) {
- $this->possibleCoreUpdateVersions = $this->getPossibleCoreUpdateVersions($core_data['existing_version'], $core_releases);
+ $this->existingCoreVersion = $core_data['existing_version'];
+ $this->possibleCoreUpdateVersions = $this->getPossibleCoreUpdateVersions($core_releases);
}
}
/**
* Gets the core versions that should be considered for compatibility ranges.
*
- * @param string $existing_version
- * The existing (currently installed) version of Drupal core.
* @param array $core_releases
* The Drupal core available releases.
*
* @return string[]
* The core version numbers that are possible to update the site to.
*/
- protected function getPossibleCoreUpdateVersions($existing_version, array $core_releases) {
- if (!isset($core_releases[$existing_version])) {
+ protected function getPossibleCoreUpdateVersions(array $core_releases) {
+ if (!isset($core_releases[$this->existingCoreVersion])) {
// If we can't determine the existing version of core then we can't
// calculate the core compatibility of a given release based on core
// versions after the existing version.
return [];
}
$core_release_versions = array_keys($core_releases);
- $possible_core_update_versions = Semver::satisfiedBy($core_release_versions, '>= ' . $existing_version);
+ $possible_core_update_versions = Semver::satisfiedBy($core_release_versions, '>= ' . $this->existingCoreVersion);
$possible_core_update_versions = Semver::sort($possible_core_update_versions);
$possible_core_update_versions = array_filter($possible_core_update_versions, function ($version) {
return VersionParser::parseStability($version) === 'stable';
@@ -131,11 +137,26 @@ class ProjectCoreCompatibility {
}
foreach ($releases_to_set as &$release) {
if (!empty($release['core_compatibility'])) {
+ $release['core_compatible'] = $this->isCoreCompatible($release['core_compatibility']);
$release['core_compatibility_message'] = $this->createMessageFromCoreCompatibility($release['core_compatibility']);
}
}
}
+ /**
+ * Determines if a release is compatible with the currently installed core.
+ *
+ * @param string $core_compatibility_constraint
+ * A semantic version constraint.
+ *
+ * @return bool
+ * TRUE if the given constraint is satisfied by the currently installed
+ * version of Drupal core, otherwise FALSE.
+ */
+ protected function isCoreCompatible($core_compatibility_constraint) {
+ return Semver::satisfies($this->existingCoreVersion, $core_compatibility_constraint);
+ }
+
/**
* Creates core a compatibility message from a semantic version constraint.
*
@@ -157,7 +178,7 @@ class ProjectCoreCompatibility {
$range_messages[] = $core_compatibility_range[0];
}
}
- $this->compatibilityMessages[$core_compatibility_constraint] = $this->t('This module is compatible with Drupal core:') . ' ' . implode(', ', $range_messages);
+ $this->compatibilityMessages[$core_compatibility_constraint] = $this->t('Requires Drupal core:') . ' ' . implode(', ', $range_messages);
}
return $this->compatibilityMessages[$core_compatibility_constraint];
}
diff --git a/core/modules/update/templates/update-version.html.twig b/core/modules/update/templates/update-version.html.twig
index 72c3174c49a9..decc9df6ec70 100644
--- a/core/modules/update/templates/update-version.html.twig
+++ b/core/modules/update/templates/update-version.html.twig
@@ -6,11 +6,21 @@
* Available variables:
* - attributes: HTML attributes suitable for a container element.
* - title: The title of the project.
+ * - core_compatibility_details: Render array of core compatibility details.
* - version: A list of data about the latest released version, containing:
* - version: The version number.
* - date: The date of the release.
* - download_link: The URL for the downloadable file.
* - release_link: The URL for the release notes.
+ * - core_compatible: A flag indicating whether the project is compatible
+ * with the currently installed version of Drupal core. This flag is not
+ * set for the Drupal core project itself.
+ * - core_compatibility_message: A message indicating the versions of Drupal
+ * core with which this project is compatible. This message is also
+ * contained within the 'core_compatibility_details' variable documented
+ * above. This message is not set for the Drupal core project itself.
+ *
+ * @see template_preprocess_update_version()
*
* @ingroup themeable
*/
@@ -21,18 +31,22 @@
diff --git a/core/themes/seven/css/theme/update-report.css b/core/themes/seven/css/theme/update-report.css
new file mode 100644
index 000000000000..0f65b18d7c77
--- /dev/null
+++ b/core/themes/seven/css/theme/update-report.css
@@ -0,0 +1,28 @@
+/**
+ * @file update-report.css
+ *
+ * Styling for the Available updates report at admin/reports/updates
+ */
+
+.project-update__compatibility-details details {
+ height: 20px;
+ margin: 2px 0;
+ border: 0;
+ background-color: inherit;
+}
+.project-update__compatibility-details details[open] {
+ overflow: visible;
+ height: auto;
+ white-space: normal;
+}
+.project-update__compatibility-details summary {
+ border: 0;
+ margin: 0;
+ padding: 0;
+ text-transform: none;
+ font-weight: normal;
+}
+.project-update__compatibility-details .details-wrapper {
+ margin: 0;
+ padding: 5px 0;
+}
diff --git a/core/themes/seven/seven.libraries.yml b/core/themes/seven/seven.libraries.yml
index 18f62e95ea0e..f26a81049bd8 100644
--- a/core/themes/seven/seven.libraries.yml
+++ b/core/themes/seven/seven.libraries.yml
@@ -83,6 +83,12 @@ maintenance-page:
- system/maintenance
- seven/global-styling
+update-report:
+ version: VERSION
+ css:
+ theme:
+ css/theme/update-report.css: {}
+
install-page:
version: VERSION
js:
diff --git a/core/themes/seven/seven.theme b/core/themes/seven/seven.theme
index 181758b78d04..7b267172a738 100644
--- a/core/themes/seven/seven.theme
+++ b/core/themes/seven/seven.theme
@@ -425,3 +425,16 @@ function seven_preprocess_image_widget(array &$variables) {
unset($data['preview']);
}
}
+
+/**
+ * Prepares variables for update version templates.
+ *
+ * Default template: update-version.html.twig.
+ *
+ * @param array $variables
+ * An associative array containing:
+ * - version: An array of information about the release version.
+ */
+function seven_preprocess_update_version(array &$variables) {
+ $variables['#attached']['library'][] = 'seven/update-report';
+}
diff --git a/core/themes/stable/templates/admin/update-version.html.twig b/core/themes/stable/templates/admin/update-version.html.twig
index f3bce70b2fd6..4b0389ea60ce 100644
--- a/core/themes/stable/templates/admin/update-version.html.twig
+++ b/core/themes/stable/templates/admin/update-version.html.twig
@@ -6,11 +6,21 @@
* Available variables:
* - attributes: HTML attributes suitable for a container element.
* - title: The title of the project.
+ * - core_compatibility_details: Render array of core compatibility details.
* - version: A list of data about the latest released version, containing:
* - version: The version number.
* - date: The date of the release.
* - download_link: The URL for the downloadable file.
* - release_link: The URL for the release notes.
+ * - core_compatible: A flag indicating whether the project is compatible
+ * with the currently installed version of Drupal core. This flag is not
+ * set for the Drupal core project itself.
+ * - core_compatibility_message: A message indicating the versions of Drupal
+ * core with which this project is compatible. This message is also
+ * contained within the 'core_compatibility_details' variable documented
+ * above. This message is not set for the Drupal core project itself.
+ *
+ * @see template_preprocess_update_version()
*/
#}