class ProfileExtensionList extends ExtensionList (View source)

internal  This class is not yet stable and therefore there are no guarantees that the internal implementations including constructor signature and protected properties / methods will not change over time. This will be reviewed after https://www.drupal.org/project/drupal/issues/2940481
 

Provides a list of installation profiles.

Properties

protected string $type

The type of the extension: "module", "theme" or "profile".

from  ExtensionList
protected string $root

The app root.

from  ExtensionList
protected CacheBackendInterface $cache

The cache.

from  ExtensionList
protected $defaults {@inheritdoc}
protected InfoParserInterface $infoParser

The info parser.

from  ExtensionList
protected ModuleHandlerInterface $moduleHandler

The module handler.

from  ExtensionList
protected Extension[]|null $extensions

The cached extensions.

from  ExtensionList
protected array[]|null $extensionInfo

Static caching for extension info.

from  ExtensionList
protected string[]|null $pathNames

A list of extension folder names keyed by extension name.

from  ExtensionList
protected string[] internal $addedPathNames

A list of extension folder names directly added in code (not discovered).

from  ExtensionList
protected StateInterface $state

The state store.

from  ExtensionList
protected string $installProfile

The install profile used by the site.

from  ExtensionList

Methods

__construct(string $root, string $type, CacheBackendInterface $cache, InfoParserInterface $info_parser, ModuleHandlerInterface $module_handler, StateInterface $state, string $install_profile)

Constructs a new instance.

getExtensionDiscovery()

Returns the extension discovery.

$this
reset()

Resets the stored extension list.

string
getListCacheId()

Returns the extension list cache ID.

string
getInfoCacheId()

Returns the extension info cache ID.

string
getPathnamesCacheId()

Returns the extension filenames cache ID.

bool
exists(string $extension_name)

Determines if an extension exists in the filesystem.

string
getName(string $extension_name)

Returns the human-readable name of the extension.

get(string $extension_name)

Returns a single extension.

getList()

Returns all available extensions.

doScanExtensions()

Scans the available extensions.

doList()

Builds the list of extensions.

array
getExtensionInfo(string $extension_name)

Returns information about a specified extension.

array[]
getAllAvailableInfo()

Returns an array of info files information of available extensions.

string[]
getInstalledExtensionNames()

Returns a list of machine names of installed extensions.

array[]
getAllInstalledInfo()

Returns an array of info files information of installed extensions.

array[]
recalculateInfo()

Generates the information from .info.yml files for extensions of this type.

string[]
getPathnames()

Returns a list of extension file paths keyed by machine name.

string[]
recalculatePathnames()

Generates a sorted list of .info.yml file locations for all extensions.

setPathname(string $extension_name, string $pathname)

Sets the pathname for an extension.

string
getPathname(string $extension_name)

Gets the info file path for an extension.

string
getPath(string $extension_name)

Gets the path to an extension of a specific type (module, theme, etc.).

array
createExtensionInfo(Extension $extension)

Creates the info value for an extension object.

bool
checkIncompatibility(string $name)

Tests the compatibility of an extension.

static int
sortByName(Extension $a, Extension $b)

Array sorting callback; sorts extensions by their name.

Details

__construct(string $root, string $type, CacheBackendInterface $cache, InfoParserInterface $info_parser, ModuleHandlerInterface $module_handler, StateInterface $state, string $install_profile)

Constructs a new instance.

Parameters

string $root

The app root.

string $type

The extension type.

CacheBackendInterface $cache

The cache.

InfoParserInterface $info_parser

The info parser.

ModuleHandlerInterface $module_handler

The module handler.

StateInterface $state

The state.

string $install_profile

The install profile used by the site.

protected ExtensionDiscovery getExtensionDiscovery()

Returns the extension discovery.

Return Value

ExtensionDiscovery

$this reset()

Resets the stored extension list.

We don't reset statically added filenames, as it is a static cache which logically can't change. This is done for performance reasons of the installer.

Return Value

$this

protected string getListCacheId()

Returns the extension list cache ID.

Return Value

string

The list cache ID.

protected string getInfoCacheId()

Returns the extension info cache ID.

Return Value

string

The info cache ID.

protected string getPathnamesCacheId()

Returns the extension filenames cache ID.

Return Value

string

The filename cache ID.

bool exists(string $extension_name)

Determines if an extension exists in the filesystem.

Parameters

string $extension_name

The machine name of the extension.

Return Value

bool

TRUE if the extension exists (regardless installed or not) and FALSE if not.

string getName(string $extension_name)

Returns the human-readable name of the extension.

Parameters

string $extension_name

The machine name of the extension.

Return Value

string

The human-readable name of the extension.

Exceptions

UnknownExtensionException

Extension get(string $extension_name)

Returns a single extension.

Parameters

string $extension_name

The machine name of the extension.

Return Value

Extension

A processed extension object for the extension with the specified machine name.

Exceptions

UnknownExtensionException

Extension[] getList()

Returns all available extensions.

Return Value

Extension[]

Processed extension objects, keyed by machine name.

protected Extension[] doScanExtensions()

Scans the available extensions.

Overriding this method gives other code the chance to add additional extensions to this raw listing.

Return Value

Extension[]

Unprocessed extension objects, keyed by machine name.

protected Extension[] doList()

Builds the list of extensions.

Return Value

Extension[]

Processed extension objects, keyed by machine name.

Exceptions

InfoParserException

array getExtensionInfo(string $extension_name)

Returns information about a specified extension.

This function returns the contents of the .info.yml file for the specified extension.

Parameters

string $extension_name

The name of an extension whose information shall be returned.

Return Value

array

An associative array of extension information.

Exceptions

UnknownExtensionException

array[] getAllAvailableInfo()

Returns an array of info files information of available extensions.

This function returns the processed contents (with added defaults) of the .info.yml files.

Return Value

array[]

An associative array of extension information arrays, keyed by extension name.

protected string[] getInstalledExtensionNames()

Returns a list of machine names of installed extensions.

Return Value

string[]

The machine names of all installed extensions of this type.

array[] getAllInstalledInfo()

Returns an array of info files information of installed extensions.

This function returns the processed contents (with added defaults) of the .info.yml files.

Return Value

array[]

An associative array of extension information arrays, keyed by extension name.

protected array[] recalculateInfo()

Generates the information from .info.yml files for extensions of this type.

Return Value

array[]

An array of arrays of .info.yml entries keyed by the machine name.

string[] getPathnames()

Returns a list of extension file paths keyed by machine name.

Return Value

string[]

protected string[] recalculatePathnames()

Generates a sorted list of .info.yml file locations for all extensions.

Return Value

string[]

An array of .info.yml file locations keyed by the extension machine name.

setPathname(string $extension_name, string $pathname)

internal  
 

Sets the pathname for an extension.

This method is used in the Drupal bootstrapping phase, when the extension system is not fully initialized, to manually set locations of modules and profiles needed to complete bootstrapping.

It is not recommended to call this method except in those rare cases.

Parameters

string $extension_name

The machine name of the extension.

string $pathname

The pathname of the extension which is to be set explicitly rather than by consulting the dynamic extension listing.

See also

::getPathname

string getPathname(string $extension_name)

Gets the info file path for an extension.

The info path, whether provided, cached, or retrieved from the database, is only returned if the file exists.

This function plays a key role in allowing Drupal's extensions (modules, themes, profiles, theme_engines, etc.) to be located in different places depending on a site's configuration. For example, a module 'foo' may legally be located in any of these four places:

  • core/modules/foo/foo.info.yml
  • modules/foo/foo.info.yml
  • sites/all/modules/foo/foo.info.yml
  • sites/example.com/modules/foo/foo.info.yml

while a theme 'bar' may be located in any of the following four places:

  • core/themes/bar/bar.info.yml
  • themes/bar/bar.info.yml
  • sites/all/themes/bar/bar.info.yml
  • sites/example.com/themes/bar/bar.info.yml

An installation profile maybe be located in any of the following places:

  • core/profiles/baz/baz.info.yml
  • profiles/baz/baz.info.yml

Calling ExtensionList::getPathname('foo') will give you one of the above, depending on where the extension is located and what type it is.

Parameters

string $extension_name

The machine name of the extension for which the pathname is requested.

Return Value

string

The drupal-root relative filename and path of the requested extension's .info.yml file.

Exceptions

UnknownExtensionException

string getPath(string $extension_name)

Gets the path to an extension of a specific type (module, theme, etc.).

The path is the directory in which the .info file is located. This name is coming from \SplFileInfo.

Parameters

string $extension_name

The machine name of the extension for which the path is requested.

Return Value

string

The Drupal-root-relative path to the specified extension.

Exceptions

UnknownExtensionException

protected array createExtensionInfo(Extension $extension)

Creates the info value for an extension object.

Parameters

Extension $extension

The extension whose info is to be altered.

Return Value

array

The extension info array.

bool checkIncompatibility(string $name)

Tests the compatibility of an extension.

Parameters

string $name

The extension name to check.

Return Value

bool

TRUE if the extension is incompatible and FALSE if not.

Exceptions

UnknownExtensionException

static int sortByName(Extension $a, Extension $b)

Array sorting callback; sorts extensions by their name.

Parameters

Extension $a

The first extension to compare.

Extension $b

The second extension to compare.

Return Value

int

Less than 0 if $a is less than $b, more than 0 if $a is greater than $b, and 0 if they are equal.