1

When I create a new field programmatically, drupal create a default schema for my being added and for each new field added is create a new database schema. I noticed that the columns always have the same structure except for the last column 'FIELD_NAME_value'.

entity_type | bundle | delete | entity_id | revision_id | language | delta | FIELD_NAME_value

I have many fields that have the same "entity_type" and "bundle".

Can I create programmatically a single schema that contains all of them?

Thanks!

0

No, it won't be recognized by Field API. By default Drupal uses Field Api and Field Storage API to store field data. It creates two tables for every new field which you create from Field UI (field_data_* and field_revision_*). If you are able to create your own Storage for Field Api then you can use it... Here are some resources:

0

I would like to point out some things to improve the answer of @xurshid29:

  1. The schema of your fields don't have to be equal or uniform. A field could contain more attributtes than you expect. Take a look to next hook, called hook_field_schema. With this hook you can add more attributes to your field, and the hook build a new column in database for each new attribute. You can find several shared modules in Drupal that apply their own fields and have a different number of columns in database.
  2. The attributes that you have noticed in the schema are common in all fields.
  3. Try to reuse fields previously created. A field could be attached to different entitys and bundles. You don't need to create, for example, a date field if you prevoiusly created one for your article content type.
  • yes, I have seen it but with hook_field_schema() I can only add more attribute to my field schema, instead I would combine two or more fields in a single schema. – user24003 Dec 15 '13 at 11:52

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.