Problem/Motivation
The module machine name is node_access_by_field_role, but the PHP classes in src/ use the Drupal\node_access_by_field namespace.
For example, the file:
web/modules/contrib/node_access_by_field_role/src/Plugin/Field/FieldType/RoleReferenceItem.php
declares:
namespace Drupal\node_access_by_field\Plugin\Field\FieldType;
This mismatch can cause Drupal's class discovery/autoloading to load the same class name through an incompatible module namespace/path. When enabling the module, installation can abort with a fatal "class already in use" error.
Error:
PHP Fatal error: Cannot declare class Drupal\node_access_by_field\Plugin\Field\FieldType\RoleReferenceItem, because the name is already in use in /var/www/html/lib/web/modules/contrib/node_access_by_field_role/src/Plugin/Field/FieldType/RoleReferenceItem.php on line 25
Steps to reproduce
1. Install Drupal 11.4 on PHP 8.3.
2. Download/install Node Access by Field Role.
3. Run: drush en -y node_access_by_field_role
Actual result
The Drush command aborts with:
Cannot declare class Drupal\node_access_by_field\Plugin\Field\FieldType\RoleReferenceItem, because the name is already in use
Expected result
The module should install without a PHP fatal error.
Proposed resolution
Update the module's PHP namespaces and service/route references to match the module machine name.
For example:
Drupal\node_access_by_field\Plugin\Field\FieldType\RoleReferenceItem
should become:
Drupal\node_access_by_field_role\Plugin\Field\FieldType\RoleReferenceItem
Comments
Comment #3
kate_raquel commentedFixed in release 1.0.2. All PHP namespaces under src/ were updated to Drupal\node_access_by_field_role to resolve the class redeclaration fatal error during installation. Thank you for reporting!