In order to avoid collisions, fields should be named modulename_fieldname. (I'm sure this is documented somewhere, but I couldn't find it - it follows general guidelines and good sense though!)

Attached patch attaches the node_example_ prefix to the color, quantity and image fields defined in node_example module.

Comments

rfay’s picture

@tanoshimi, glad to have you participating. Thanks for the patch!

If you want this change, though, please point to a reference in the coding standards (or some other source) that justifies this.

Thanks,
-Randy

tanoshimi’s picture

I can't find it written in plain black and white, however I can find two things to support this:

1.) From: http://api.drupal.org/api/group/field_structs/7
"field_name (string) The name of the field. Each field name is unique within Field API."
Prefixing each field with the name of the module that created it ensures that this statement remains true when a module defines a new field (and that there isn't, for example, another module that defines a "color", "quantity" or "image" field).

2.) This is the convention followed by all the fields shipped with D7 core - the tags fields defined by taxonomy module is taxonomy_tags, the image field defined by field module is field_image etc.

rfay’s picture

+1: I'd say that's an adequate argument. You should perhaps file an issue to get that convention added to the coding standards or somewhere, as it is perfectly logical.

It's one of those things that's new to D7, so hasn't yet been properly addressed. I encourage you to chat with yched and bjaspan about how to get this documented and agreed upon.

Status: Needs review » Needs work

The last submitted patch, examples_nodeprefix.patch, failed testing.

tanoshimi’s picture

Status: Needs work » Needs review
StatusFileSize
new2.13 KB

let's have another go...

Status: Needs review » Needs work

The last submitted patch, examples_nodeprefix2.patch, failed testing.

rfay’s picture

@tanoshimi, it looks like you updated the module but forgot to update the test:
http://qa.drupal.org/pifr/test/40558

Please reroll, and it avoids frustration to run the tests on your local machine.

Thanks!
-Randy

tanoshimi’s picture

Hi Randy -

Thanks - I realised that I forgot to update the test but was waiting for confirmation of #746328: Document coding standards for field naming (D7) before resubmitting (also think that the token test might have been broken when last submitted)

rfay’s picture

rfay’s picture

@tanoshimi, I think this will be fine regardless of the non-status of #746328: Document coding standards for field naming (D7). Go for it.

tanoshimi’s picture

Status: Needs work » Needs review
StatusFileSize
new3.21 KB

Ok. Third try lucky... fingers crossed!

Status: Needs review » Needs work

The last submitted patch, node_example_field_prefix.patch, failed testing.

rfay’s picture

The queue_example #fail is (almost) certainly not your fault - I'm retesting HEAD to see: http://qa.drupal.org/pifr/test/26934

Thanks for your work on this! You're almost there!

rfay’s picture

Update: Looks like HEAD is broken: http://qa.drupal.org/pifr/test/26934

I'll take a look at it and then resubmit this one after HEAD is fixed.

rfay’s picture

Almost got HEAD working, but still one #fail.

rfay’s picture

Status: Needs work » Needs review

#11: node_example_field_prefix.patch queued for re-testing.

rfay’s picture

Status: Needs review » Fixed

Committed to HEAD: http://drupal.org/cvs?commit=372806

Thanks! I look forward to more contributions from you to make this project better.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.