Naming conventions for Entities and how to take take decisions while reviewing Project Applications?

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
D34dMan's picture

This http://drupal.org/node/1603204 document on drupal.org sounds more like a guideline while developing custom modules for personal use or using the UI to create entities.

When i asked about entity naming convention in #drupal-contribute, xano told me that everything ( entity machine name ) should be prefixed with module name.

While checking a project application, it was found that it used "watchdog" as an entity name. Should it be allowed?

Should

  1. Is it a must that "Machine name of every entity declared by a module should be prefixed with the module name." ? Or,
  2. We can relax and allow watchdog and similar names for entities, which are not necessarily prefixed with module name ?

Comments

D6, D7 required, D8 depends

sreynen's picture

The reason for using module names as machine name prefixes is ensuring unique machine names. If two modules use the same machine names, bad things generally happen. Depending on what the machine names are being used for, those bad things can include making the entire site completely unusable. So in general, yes, module prefixing of machine names should be required. The specific application you're looking at may be an odd exception for some reason, but the applicant should at least be able to explain that reason if that's the case.

Looking forward, in D8 we're starting to use proper namespaces, which will allow two module to use the same names for some things without any problems. When we get into this code, the module prefixing won't be relevant in some cases, though it will still matter in other cases, so answering this question will become more complicated.

D34dMan's picture

Thanks sreynen, even i had a feeling it should be mandatory. But when a reviewer mentioned that in his review, his request ( to change the machine name 'watchdog' and prefix it with module name ) was turned down due to lack of his experience ( the reviewer's profile was dated 5 years back though ) on the subject matter.

The specific application you're looking at may be an odd exception for some reason, but the applicant should at least be able to explain that reason if that's the case.

So when deciding on whether to allow it or not, should it be reviewer's responsibility to find a failing test case?

Also i find that personally allowing such entity naming just because it doesn't fails against drupal core, doesn't rules out a possibility of conflict with another contrib project. Like for example another module decides to use the same machine-name!

No, the reviewer is not

klausi's picture

No, the reviewer is not responsible for finding a name collision. It is a bit unfortunate that I could not find any documentation about name spacing entity names, maybe someone else can point me to a resource?

Anyway, I would consider improper naming an application blocker, same for constants, function names, variable names etc. The Drupal contrib universe would just break down if projects would not stick to their own name space.