final class ProjectCoreCompatibility (View source)

internal  This class implements logic used by update_calculate_project_status(). It should not be called directly.
 

Utility class to set core compatibility messages for project releases.

Traits

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Properties

protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected string $existingCoreVersion

The currently installed version of Drupal core.

protected string[] $possibleCoreUpdateVersions

Cache of core versions that are available for updates.

protected string[] $compatibilityMessages

Cache of core compatibility messages per core version constraint.

Methods

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

__construct(array $core_data, array $core_releases)

Constructs a ProjectCoreCompatibility object.

string[]
getPossibleCoreUpdateVersions(array $core_releases)

Gets the core versions that should be considered for compatibility ranges.

setReleaseMessage(array $project_data)

Sets core compatibility messages for project releases.

bool
isCoreCompatible(string $core_compatibility_constraint)

Determines if a release is compatible with the currently installed core.

string
createMessageFromCoreCompatibility(string $core_compatibility_constraint)

Creates core a compatibility message from a semantic version constraint.

array[]
getCompatibilityRanges(string $core_compatibility_constraint)

Gets the compatibility ranges for a semantic version constraint.

Details

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

__construct(array $core_data, array $core_releases)

Constructs a ProjectCoreCompatibility object.

Parameters

array $core_data

The project data for Drupal core as returned by \Drupal\update\UpdateManagerInterface::getProjects() and then processed by update_process_project_info() and update_calculate_project_update_status().

array $core_releases

The Drupal core available releases.

See also

UpdateManagerInterface::getProjects
update_process_project_info()
update_calculate_project_update_status()

protected string[] getPossibleCoreUpdateVersions(array $core_releases)

Gets the core versions that should be considered for compatibility ranges.

Parameters

array $core_releases

The Drupal core available releases.

Return Value

string[]

The core version numbers that are possible to update the site to.

setReleaseMessage(array $project_data)

Sets core compatibility messages for project releases.

Parameters

array $project_data

The project data as returned by \Drupal\update\UpdateManagerInterface::getProjects() and then processed by update_process_project_info() and update_calculate_project_update_status(). If set, the following keys are used in this method:

  • recommended (string): A project version number.
  • latest_version (string): A project version number.
  • also (string[]): Project version numbers.
  • releases (array[]): An array where the keys are project version numbers and the values are arrays of project release information.
  • security updates (array[]): An array of project release information.

See also

UpdateManagerInterface::getProjects
update_process_project_info()
update_calculate_project_update_status()

protected bool isCoreCompatible(string $core_compatibility_constraint)

Determines if a release is compatible with the currently installed core.

Parameters

string $core_compatibility_constraint

A semantic version constraint.

Return Value

bool

TRUE if the given constraint is satisfied by the currently installed version of Drupal core, otherwise FALSE.

protected string createMessageFromCoreCompatibility(string $core_compatibility_constraint)

Creates core a compatibility message from a semantic version constraint.

Parameters

string $core_compatibility_constraint

A semantic version constraint.

Return Value

string

The core compatibility message.

protected array[] getCompatibilityRanges(string $core_compatibility_constraint)

Gets the compatibility ranges for a semantic version constraint.

Parameters

string $core_compatibility_constraint

A semantic version constraint.

Return Value

array[]

An array compatibility ranges. If a range array has 2 elements then this denotes a range of compatibility between and including the 2 versions. If the range has 1 element then it denotes compatibility with a single version.