diff -u b/core/modules/update/src/ProjectCoreCompatibility.php b/core/modules/update/src/ProjectCoreCompatibility.php --- b/core/modules/update/src/ProjectCoreCompatibility.php +++ b/core/modules/update/src/ProjectCoreCompatibility.php @@ -139,33 +139,62 @@ 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']); - $release['core_compatibility_details'] = [ - '#type' => 'details', - '#title' => $release['core_compatible'] ? $this->t('Compatible') : $this->t('Not compatible'), - '#open' => FALSE, - 'message' => [ - '#markup' => $release['core_compatibility_message'], - ], - '#attributes' => [ - 'class' => [ - $release['core_compatible'] ? 'compatible' : 'not-compatible', - ], - ], - ]; - if (!$release['core_compatible']) { - $release['core_compatibility_details']['not-compatible'] = [ - '#weight' => -10, - '#markup' => $this->t('Your version of Drupal core (%version) is not compatible with this update.', ['%version' => $this->existingCoreVersion]), - '#prefix' => '
', - '#suffix' => '
', - ]; - } + $release['core_compatibility_details'] = $this->createCoreCompatibilityDetails($release['core_compatibility'], $release['core_compatible']); } } } /** + * Creates core a compatibility details element. + * + * @param string $core_compatibility_constraint + * A semantic version constraint. + * @param boolean $core_compatible + * Is the release compatible with the currently installed version of core? + * + * @return array + * Render array of the core compatibility details element. + * + * @todo Should this be a twig template? + */ + protected function createCoreCompatibilityDetails($core_compatibility_constraint, $core_compatible) { + $element = [ + '#type' => 'details', + 'compatibility_range' => [ + '#markup' => $this->createMessageFromCoreCompatibility($core_compatibility_constraint), + ], + ]; + if ($core_compatible) { + $element += [ + '#title' => $this->t('Compatible'), + '#open' => FALSE, + ]; + $compatibility_intro = $this->t('Your version of Drupal core (%version) is compatible with this update.', ['%version' => $this->existingCoreVersion]); + } + else { + $element += [ + '#title' => $this->t('Not compatible'), + '#open' => TRUE, + ]; + $compatibility_intro = $this->t('Your version of Drupal core (%version) is not compatible with this update.', ['%version' => $this->existingCoreVersion]); + } + $element += [ + 'intro' => [ + '#weight' => -10, + '#markup' => $compatibility_intro, + '#prefix' => '', + '#suffix' => '
', + ], + '#attributes' => [ + 'class' => [ + $core_compatible ? 'compatible' : 'not-compatible', + ], + ], + ]; + return $element; + } + + /** * Creates core a compatibility message from a semantic version constraint. * * @param string $core_compatibility_constraint