Skip to content

Commit 37ee92d

Browse files
authored
Update to working example with Simplenews, prepare for Drupal 12 (#34)
* Update README.md to Drupal 11 Also, switch from Token to Simplenews, which is not Drupal 11 ready. * Update PackageRequiresAdjusterTest.php * Update PackageRequiresAdjuster.php
1 parent 6f9e03f commit 37ee92d

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

README.md

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# mglaman/composer-drupal-lenient
1+
# Drupal Lenient Composer Plugin
22

3-
Lenient with it, Drupal 10 with it.
3+
Lenient with it, Drupal 11 with it.
44

55
## Why?
66

@@ -9,7 +9,9 @@ was done to remove a barrier with getting extensions installed via Composer to w
99

1010
We hit the same problem, again. At DrupalCon Portland we sat down and decided a Composer plugin is the best approach.
1111

12-
See [Add a composer plugin that supports 'composer require-lenient' to support major version transitions](https://www.drupal.org/project/drupal/issues/3267143)
12+
See [Add a composer plugin that supports 'composer require-lenient' to support major version transitions](https://www.drupal.org/project/drupal/issues/3267143).
13+
14+
Drupal documentation page: [Using Drupal's Lenient Composer Endpoint](https://www.drupal.org/docs/develop/using-composer/using-drupals-lenient-composer-endpoint).
1315

1416
## How
1517

@@ -19,30 +21,35 @@ excluding `drupal-core`. The constraint is set to `'^8 || ^9 || ^10 || ^11'` for
1921

2022
## Try it
2123

22-
Setup a fresh Drupal 10 site with this plugin (remember to press `y` for the new `allow-plugins` prompt.)
24+
Set up a fresh Drupal 11 site with this plugin (remember to press `y` for the new `allow-plugins` prompt.)
2325

2426
```shell
25-
composer create-project drupal/recommended-project:^10@alpha d10
26-
cd d10
27-
composer config minimum-stability dev
27+
composer create-project drupal/recommended-project d11
28+
cd d11
2829
composer require mglaman/composer-drupal-lenient
2930
```
3031

3132
The plugin only works against specified packages. To allow a package to have a lenient Drupal core version constraint,
32-
you must add it to `extra.drupal-lenient.allowed-list`. The following is an example to add Token via the command line
33+
you must add it to `extra.drupal-lenient.allowed-list`. The following is an example to add Simplenews via the command line
3334
with `composer config`
3435

3536
```shell
36-
composer config --merge --json extra.drupal-lenient.allowed-list '["drupal/token"]'
37+
composer config --merge --json extra.drupal-lenient.allowed-list '["drupal/simplenews"]'
3738
```
3839

39-
Now, add a module that does not have a D10 compatible release!
40+
Now, add a module that does not have a Drupal 11 compatible release!
4041

4142
```shell
42-
composer require drupal/token:1.10.0
43+
composer require drupal/simplenews
4344
```
4445

45-
🥳 Now you can use [cweagans/composer-patches](https://github.com/cweagans/composer-patches) to patch the module for Drupal 10 compatibility!
46+
🥳 Now you can use [cweagans/composer-patches](https://github.com/cweagans/composer-patches) to patch the module for Drupal 11 compatibility!
47+
48+
For a quick start, allow installation by adding the latest version in the module `*.info.yml` file:
49+
50+
```shell
51+
core_version_requirement: ^9.3 || ^10 || ^11
52+
```
4653

4754
## Support when `composer.lock` removed
4855

src/PackageRequiresAdjuster.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(
2222
private readonly Composer $composer
2323
) {
2424
$this->drupalCoreConstraint = (new VersionParser())
25-
->parseConstraints('^8 || ^9 || ^10 || ^11');
25+
->parseConstraints('^8 || ^9 || ^10 || ^11 || ^12');
2626
}
2727

2828
public function applies(PackageInterface $package): bool

tests/PackageRequiresAdjusterTest.php

+10-9
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ public function testAdjust(?string $coreVersion, string $expectedCoreConstraintS
8787
new Constraint('>=', '8.0'),
8888
new Constraint('>=', '9.0'),
8989
new Constraint('>=', '10.0'),
90+
new Constraint('>=', '11.0'),
9091
]);
91-
$originalTokenConstraint = new Constraint('>=', '1.10.0');
92+
$originalSimplenewsConstraint = new Constraint('>=', '4.0.0');
9293
$package = new CompletePackage('foo', '1.0', '1.0');
9394
$package->setType('drupal-module');
9495
$package->setRequires([
@@ -99,12 +100,12 @@ public function testAdjust(?string $coreVersion, string $expectedCoreConstraintS
99100
Link::TYPE_REQUIRE,
100101
$originalDrupalCoreConstraint->getPrettyString()
101102
),
102-
'drupal/token' => new Link(
103+
'drupal/simplenews' => new Link(
103104
'bar',
104-
'drupal/token',
105-
$originalTokenConstraint,
105+
'drupal/simplenews',
106+
$originalSimplenewsConstraint,
106107
Link::TYPE_REQUIRE,
107-
$originalTokenConstraint->getPrettyString()
108+
$originalSimplenewsConstraint->getPrettyString()
108109
)
109110
]);
110111
$adjuster->adjust($package);
@@ -113,8 +114,8 @@ public function testAdjust(?string $coreVersion, string $expectedCoreConstraintS
113114
$package->getRequires()['drupal/core']->getConstraint()->getPrettyString()
114115
);
115116
self::assertSame(
116-
$originalTokenConstraint,
117-
$package->getRequires()['drupal/token']->getConstraint()
117+
$originalSimplenewsConstraint,
118+
$package->getRequires()['drupal/simplenews']->getConstraint()
118119
);
119120
if ($coreVersion !== null) {
120121
self::assertTrue(
@@ -129,8 +130,8 @@ public function testAdjust(?string $coreVersion, string $expectedCoreConstraintS
129130
public function provideAdjustData(): array
130131
{
131132
return [
132-
[null, '^8 || ^9 || ^10 || ^11'],
133-
['10.0.0-alpha5', '^8 || ^9 || ^10 || ^11'],
133+
[null, '^8 || ^9 || ^10 || ^11 || ^12'],
134+
['10.0.0-alpha5', '^8 || ^9 || ^10 || ^11 || ^12'],
134135
];
135136
}
136137
}

0 commit comments

Comments
 (0)