9

While adding new fields to a content type, When should I resue an existing field? for example if I need an image field for my content type is it always a good idea to re-use an existing image field?

  • 3
    if it's going to be used in the same way, accessible to the same users/roles, be themed the same way, etc, then yes, it will be much easier to maintain if you reuse the same field. – Jimajamma Feb 21 '12 at 17:08
  • 1
    but if an image is going to be, for example, a user photo in one content type, but a thumbnail of a product image in another, then no, create different fields. – Jimajamma Feb 21 '12 at 17:08
  • 1
  • @Jimajamma Are you sure about the second comment? I think it can be configured in display settings of content type. – hknik Feb 21 '12 at 19:41
  • sure, it can be displayed anyway you want it, my comment is to the name of the field. eg, field_avatar being used as the profile image of a user in one content type being overloaded as a product thumbnail in another type just is confusing from a naming perspective. – Jimajamma Feb 21 '12 at 19:54
8

Consider the benefits and drawbacks of reusing fields:

  • Performance: There's a slight performance gain from reusing fields. However, for most sites with moderate numbers of fields, it's a negligible difference.
  • Maintainability: In theory, if you re-use the same field for the same purpose on multiple content types, then if you decide to change its functionality later, you only have to change it in one place. Similarly, if you want to theme it the same way across entities, you only have to use a single selector. In practice, this rarely happens, and more often the converse is true- you've used the same field in multiple places, and then realize that they actually need to behave differently.
  • Setup: Obviously, it takes less time to re-add an existing field than to add a new one.
  • Portability: If you export fields with Features, it's best to not reuse them between entities unless absolutely necessary. Technically, there's nothing wrong with reusing fields (since you can export field bases and field instances separately), but in practice it tends to just lead to confusion and circular dependencies. If you choose not to reuse fields, then you have the luxury of being able to prefix them with the content type / bundle they are attached to, e.g. "field_article_image", "field_page_taxonomy", etc..., which eases portability and maintenance.

In case it's not clear from my tone there, my preference is to never reuse fields unless it's totally, completely, 100% clear that they really are, and forever will be, used for the same purpose.

  • Agreed. Also if you have different field settings say one image has only 1 while the other can use unlimited, if you change the field it changes all instances of it. – chadpeppers Apr 27 '14 at 3:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.