Skip to content
Snippets Groups Projects
Commit 305ed676 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2205271 by trobey, jhedstrom: Project namespace for dependencies

parent 02d58f6a
No related branches found
No related tags found
No related merge requests found
......@@ -27,7 +27,16 @@ interface InfoParserInterface {
* - type: whether it is for a module or theme. (Required)
*
* Information stored in a module .info.yml file:
* - dependencies: An array of shortnames of other modules this module requires.
* - dependencies: An array of dependency strings. Each is in the form
* 'project:module (versions)'; with the following meanings:
* - project: (optional) Project shortname, recommended to ensure
* uniqueness, if the module is part of a project hosted on drupal.org.
* If omitted, also omit the : that follows. The project name is currently
* ignored by Drupal core but is used for automated testing.
* - module: (required) Module shortname within the project.
* - (versions): Version information, consisting of one or more
* comma-separated operator/value pairs or simply version numbers, which
* can contain "x" as a wildcard. Examples: (>=8.22, <8.28), (8.x-3.x).
* - package: The name of the package of modules this module belongs to.
*
* See forum.info.yml for an example of a module .info.yml file.
......
......@@ -631,7 +631,12 @@ protected function verifyImplementations(&$implementations, $hook) {
* Parses a dependency for comparison by drupal_check_incompatibility().
*
* @param $dependency
* A dependency string, for example 'foo (>=8.x-4.5-beta5, 3.x)'.
* A dependency string, which specifies a module dependency, and optionally
* the project it comes from and versions that are supported. Supported
* formats include:
* - 'module'
* - 'project:module'
* - 'project:module (>=version, version)'
*
* @return
* An associative array with three keys:
......@@ -646,6 +651,12 @@ protected function verifyImplementations(&$implementations, $hook) {
* @see drupal_check_incompatibility()
*/
public static function parseDependency($dependency) {
$value = array();
// Split out the optional project name.
if (strpos($dependency, ':') !== FALSE) {
list($project_name, $dependency) = explode(':', $dependency);
$value['project'] = $project_name;
}
// We use named subpatterns and support every op that version_compare
// supports. Also, op is optional and defaults to equals.
$p_op = '(?<operation>!=|==|=|<|<=|>|>=|<>)?';
......@@ -654,7 +665,6 @@ public static function parseDependency($dependency) {
$p_major = '(?<major>\d+)';
// By setting the minor version to x, branches can be matched.
$p_minor = '(?<minor>(?:\d+|x)(?:-[A-Za-z]+\d+)?)';
$value = array();
$parts = explode('(', $dependency, 2);
$value['name'] = trim($parts[0]);
if (isset($parts[1])) {
......
......@@ -14,6 +14,22 @@
* @group Module
*/
class DependencyTest extends ModuleTestBase {
/**
* Checks functionality of project namespaces for dependencies.
*/
function testProjectNamespaceForDependencies() {
$edit = array(
'modules[Core][filter][enable]' => TRUE,
);
$this->drupalPostForm('admin/modules', $edit, t('Save configuration'));
// Enable module with project namespace to ensure nothing breaks.
$edit = array(
'modules[Testing][system_project_namespace_test][enable]' => TRUE,
);
$this->drupalPostForm('admin/modules', $edit, t('Save configuration'));
$this->assertModules(array('system_project_namespace_test'), TRUE);
}
/**
* Attempts to enable the Content Translation module without Language enabled.
*/
......
name: 'System project namespace'
type: module
description: 'Support module for testing project namespace system dependencies.'
package: Testing
version: VERSION
core: 8.x
dependencies:
- drupal:filter
......@@ -499,6 +499,7 @@ public function dependencyProvider() {
array('views_ui(<= 8.x-1.x)', array('name' => 'views_ui', 'original_version' => ' (<= 8.x-1.x)', 'versions' => array(array('op' => '<=', 'version' => '2.x')))),
array('views_ui( <=8.x-1.x)', array('name' => 'views_ui', 'original_version' => ' ( <=8.x-1.x)', 'versions' => array(array('op' => '<=', 'version' => '2.x')))),
array('views_ui(>8.x-1.x)', array('name' => 'views_ui', 'original_version' => ' (>8.x-1.x)', 'versions' => array(array('op' => '>', 'version' => '2.x')))),
array('drupal:views_ui(>8.x-1.x)', array('project' => 'drupal', 'name' => 'views_ui', 'original_version' => ' (>8.x-1.x)', 'versions' => array(array('op' => '>', 'version' => '2.x')))),
);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment