New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rethink the namespace for Entity Bundle Classes #74
Comments
A bit of a stretch to appeal to "established best practices". Slight -1 from me. I like using a new namespace here. Its easier to delete the dir and regenerate classes. |
Entity Bundle Classes is still a pretty new thing so I doubt that best practices are already established on this. Personally I have no opinion about that. So I am ok to change this If considerable number of people request it. |
Personally, I'm fine with the new namespace. But e.g. Drupal Core doesn't use it this way, e.g. in core/modules/system/tests/modules/entity_test_bundle_class/src/Entity:
|
Currently doing some work on a pretty large codebase, I'd even introduce one more level for the namespace: the entity type! So we'd end up with something like Drupal/mymodule/entity/Bundle/media or Drupal/mymodule/entity/Bundle/node Really, it's totally opinionated - but what could be a reasonable default? |
I think the entity type is a reasonable improvement. I'm dealing with a jumble of entity types in same folder right now. |
I wonder if "Bundle" suffix was a good idea. In Drupal bundles are configuration entities. So "ArticleBundle" sounds like a bundle configuration entity for nodes. |
I would now drop them in a If every which way the editor provided class jumping into this file I would say the namespace didn't matter. But since entity bundle classes provide public getFunctions to twig files it's still useful to provide a more descriptive namespace for the developer to find the right file. I think as well that the Bundle suffix of the class name is not needed. |
I have been using entity bundle classes for about 4 years now, even before it landed in Drupal core. I always stuck to the |
The generator has been updated in 3.x branch.
Thank you all for feedback. |
For now, entity bundle classes generated by DCG 2 are placed in the namespace Drupal\mymodule\Entity\Bundle:
However, most documentation and blog posts I've seen for now favor putting them directly in the 'Entity' namespace. Here's an excellent example: https://www.hashbangcode.com/article/drupal-9-entity-bundle-classes.
This is highly opinionated, but IMHO DCG should follow established best practices, so I'd suggest changing the namespace.
The text was updated successfully, but these errors were encountered: