- Issue created by @liliplanet
- 🇩🇪Germany jurgenhaas Gottmadingen
We're running into the same issue on Drupal core 10.2.7. Here is what happens:
- in D10.2.7, the book module is still in core and uses annotations for validation plugins
- there is now also a public release of the book module, which works with all Drupal versions >= 10
- the json_api_book module requires the book module which came from core in the past and should be coming from the contrib module in the future
- because of json_api_book, composer now also installs the book module from contrib
- as a result, we have the book module with the same namespace twice: one time in core and another time in contrib
- the contrib version uses attributes instead of annotations, and that's why Drupal doesn't find the plugins
Workaround, until we can upgrade to Drupal 10.3:
- delete web/core/modules/book after composer update or composer install
- apply a patch to bring back annotations into the validation plugin in contrib
- 🇩🇪Germany jurgenhaas Gottmadingen
For anyone who wants to use the same workaround, attached is a copy of the working constraint plugin, remove the
.txt
extension after downloading it. Then copy that into the config directory of the project root. In composer.json add 2 scripts:{ "scripts": { "post-update-cmd": "rm -rf web/core/modules/book && cp config/BookOutlineConstraint.php web/modules/contrib/book/src/Plugin/Validation/Constraint/BookOutlineConstraint.php", "post-install-cmd": "rm -rf web/core/modules/book && cp config/BookOutlineConstraint.php web/modules/contrib/book/src/Plugin/Validation/Constraint/BookOutlineConstraint.php" } }
That way it works for now, but it's not a solution to the general problem.
- 🇩🇪Germany jurgenhaas Gottmadingen
WRT the real solution, the version constraint for this module should have been that it only works with Drupal core >= 10.3 because the used constraint plugin uses an attribute which isn't available in earlier Drupal core versions. Problem is that this can't be corrected now. Even if there were a new release with that constraint, the 1.0.0 release would still be found by composer and then used for the older Drupal core versions.
- 🇩🇪Germany jurgenhaas Gottmadingen
Turns out, my workaround only works on PHP 8.1, it fails on PHP 8.2 with reflection class exceptions.
However, that leads towards a proper solution, that I didn't see before: for Drupal core <10.3 we need to remove the attribute usage from the validation plugin and bring back the annotations. That needs to be done both in Drupal core and in the contrib book module.
Then we need the following releases:
- Drupal core: we need 9.2.8 with that being fixed
- Book contrib module: 1.0.1 with that being fixed and a version constraint on Drupal core for >= 10 and <= 10.3
- Book contrib module: 1.1.0 and 2.0.0 with the attributes left in but a version constraint on Drupal core for >= 10.3
As a work around for site owners: use the BookOutlineConstraint.php file from #3 and add the 2 scripts to the root composer.json:
{ "scripts": { "post-update-cmd": "cp config/BookOutlineConstraint.php web/core/modules/book/src/Plugin/Validation/Constraint/BookOutlineConstraint.php && cp config/BookOutlineConstraint.php web/modules/contrib/book/src/Plugin/Validation/Constraint/BookOutlineConstraint.php", "post-install-cmd": "cp config/BookOutlineConstraint.php web/core/modules/book/src/Plugin/Validation/Constraint/BookOutlineConstraint.php && cp config/BookOutlineConstraint.php web/modules/contrib/book/src/Plugin/Validation/Constraint/BookOutlineConstraint.php" } }
This works for Drupal core < 10.3
- 🇨🇦Canada mparker17 UTC-4
I can also confirm this error on Drupal 10.2.7.
Note that Drupal 10.2 will be supported for security fixes until the Week of December 9, 2024 → .
For now, I think we could solve this problem by either:
- switching back to the comment-based annotation in
src/Plugin/Validation/Constraint/BookOutlineConstraint.php
, or - drop support for 10.2 before its official end-of-life (i.e.: by changing the
core_version_requirement
inbook.info.yml
)
... do the maintainers have a preference? I can write a patch.
- switching back to the comment-based annotation in
- Status changed to Needs review
3 months ago 5:58pm 9 August 2024 - 🇨🇦Canada mparker17 UTC-4
Updated the issue summary.
Setting to "Needs review" for ideas on whether we should switch back to comment-based annotations, or drop 10.2 support before its EOL.
For what it's worth, I'm in favour of switching back to comment-based annotations to give people on 10.2 more time to upgrade.
- 🇨🇦Canada joseph.olstad
Is this issue strictly related to book 2 or does it also affect book 1?
I'm seeing something a bit different in this issue I'm marking as "related"
- 🇨🇦Canada mparker17 UTC-4
This affects both book-1.0.x and book-2.0.x, because both have
core_version_requirement: '>=10 || ^11'
(1.0.x, 2.0.x) and both use attribute-based annotations (1.0.x, 2.0.x).I happened to run into this while I was testing the sitemap module (which I maintain) on drupal-10.2.7 with book-1.0.0 - so that is how I wrote the test case - but @Liliplanet filed it against book-2.0.x, and I noticed the code was the same in both branches, so I left the Version field alone.
- 🇺🇸United States smustgrave
Think since 2.0.x has no release putting a requirement of 10.3 would be best. For the attribute replacements
- 🇺🇸United States smustgrave
Okay this is probably ready to merge and can do an alpha1 release for 2.0.x
Will have to fix the tests for next minor and next major
-
smustgrave →
committed f4f52caf on 2.0.x
Resolve #3456958 "Bookoutline plugin does"
-
smustgrave →
committed f4f52caf on 2.0.x
- Status changed to Fixed
3 months ago 12:24pm 4 September 2024 - 🇺🇸United States smustgrave
Believe we have fix for the failing tests but need the changes here.
- 🇳🇱Netherlands megachriz
@smustgrave
Thanks for the update, but the issue remains that requirements fordrupal/book:^1.0
are incorrect.I ran into this when trying to test my contrib project with Drupal 10.2, 10.3 and 11.0. Tests were failing on 11.0 when not requiring "drupal/book" and failing on 10.2 when requiring "drupal/book".
I fixed this by creating a bridge package called "megachriz/drupalbook", a tip that I found on https://stackoverflow.com/questions/51333587/php-composer-require-depend.... By requiring that instead of drupal/book, I'll get drupal/book on Drupal 11 tests only.
But it would have been easier if drupal/book was compatible with Drupal 10.2.
- 🇺🇸United States smustgrave
1.0.x is a copy of core and goal is to leave that relatively untouched.
Also in 10.2 book is still in core to be used.
- 🇳🇱Netherlands megachriz
Okay, just saying that it created extra work for making modules that depend or integrate with the book module to be compatible with both Drupal 11 and Drupal 10.2. As a module maintainer, you need to require a bridge package in this case.
On the other hand, grabbing the core book module from Drupal 10.2.x and put that into book 1.x may require some extra work too: I'm not sure if that could just be copied 1 on 1 or if that requires additional changes (like cleaning up references). And I don't know if core book module from Drupal 10.2 would be compatible with Drupal 10.3 or Drupal 11.
Automatically closed - issue fixed for 2 weeks with no activity.
- 🇮🇳India maniesraj
As @jurgenhaas mention in the comment #5, that works for me, I have added a patch it.