We have a project with "drupal-composer/drupal-scaffold", where contrib modules go to "web/modules/contrib/".
There is a top-level '/src/' directory with classes used for cli operations, mapped to a custom namespace specific to this project.
The entity_meta_relation has a composer.json which maps 'Drupal\\emr\\' to './src'.
For some reason, in vendor/composer/autoload_psr4.php this results in 'Drupal\\emr\\' => array($baseDir . '/src'),.
I imagine this problem could be gone once we move to Drupal 9, and "drupal/core-composer-scaffold", which we are doing right now.
But do we really need this mapping in composer.json for entity_meta_relation?
In general, this should be added automatically by Drupal.
If needed for test runs, the mapping could be added in autoload-dev instead.
Comments
Comment #2
donquixote commentedActually it is still happening with Drupal 9 and "drupal/core-composer-scaffold".
In
vendor/composer/autoload_psr4.php:Comment #3
donquixote commentedComment #4
aporieScratching my head with this for a while, I wonder if it's not connected to: https://github.com/composer/composer/issues/4404.
Though, in my docker I do have my working folder mounted as a volume, so entity_meta_relation should return its relative path (modules/contrib/entity_meta_relation) and not the root one ...
Also, why it's only happening with this module?
Comment #5
julien tekrane commentedThis is still an ongoing issue
Comment #6
joanpebupe commentedYes, I can confirm, this is still happening.
As said by @donquixote, maybe this is not impacting the module itself cause Drupal is able to load it by its own, but it is appearing when including custom namespaces inside a docroot src/ folder.
Could be this is related to an old renaming of this module from drupal/emr into drupal/entity_meta_relation?
Thanks in advance.
Comment #7
keszthelyi commentedI also have the same issue, emr messing up the top level src directory custom project namespace, causing
PHP Fatal error: Cannot declare class...errors for certain scripts.I digged into the composer autoload generation, and after some debugging, I found that in my case it was not this module that caused the issue, but the fact that this module was a dependency for another module (OE Listing page). That module is requiring a metapackage called 'emr', that doesn't have an install path, because of this an empty string will be used by composer in the packageMap here, and that results in the
'Drupal\\emr\\' => array($baseDir . '/src'), in the autoload file.Not sure in what context others have this problem, but after I found this, I installed the module alone (not as a dependency), and could not reproduce the issue anymore.
I ended up replacing the emr metapackage and requiring entity_meta_relation directly in my project's composer.json to be able to use the module.
Comment #8
joanpebupe commentedHey @keszthelyi could you please confirm, then if requiring drupal/entity_meta_relation you have an entry for it in composer autoload_psr4 or if it is working by being loaded by Drupal itself?
I guess, then that issue should be reported as an issue about the dependency definition for oe_list_pages.
Comment #9
keszthelyi commentedHi @joanpebupe, when requiring drupal/entity_meta_relation directly, then there's no entry in autoload_psr4.php and it's working by being loaded by Drupal. Yes, I'm planning to report this on oe_list_pages.
Comment #10
joanpebupe commentedHi @keszthelyi, I guess then that if oe_lists_pages fixes its dependcy to request drupal/entity_meta_relation instead of drupal/emr that issue could be closed as seems that module (by its own) would be working as expected.
Issue opened in oe_list_pages side: https://github.com/openeuropa/oe_list_pages/issues/176