function InstalledPackage::getProjectName
Returns the Drupal project name for this package.
This assumes that drupal.org adds a `project` key to every `.info.yml` file in the package, regardless of where they are in the package's directory structure. The package name is irrelevant except for checking that the vendor is `drupal`. For example, if the project key in the info file were `my_module`, and the package name were `drupal/whatever`, and this method would return `my_module`.
Return value
string|null The name of the Drupal project installed by this package, or NULL if:
- The package type is not one of `drupal-module`, `drupal-theme`, or `drupal-profile`.
- The package's vendor is not `drupal`.
- The project name could not otherwise be determined.
Throws
\UnexpectedValueException Thrown if the same project name exists in more than one package.
File
-
core/
modules/ package_manager/ src/ InstalledPackage.php, line 71
Class
- InstalledPackage
- A value object that represents an installed Composer package.
Namespace
Drupal\package_managerCode
public function getProjectName() : ?string {
// Only consider packages which are packaged by drupal.org and will be
// known to the core Update module.
$drupal_package_types = [
'drupal-module',
'drupal-theme',
'drupal-profile',
];
if ($this->path && str_starts_with($this->name, 'drupal/') && in_array($this->type, $drupal_package_types, TRUE)) {
return $this->scanForProjectName();
}
return NULL;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.