I'm currently working a custom user registration module for a project I'm busy with. I need to add a boolean field which will be attached to user entities. The value will just serve as a flag to check whether a user has answered a CAPTCHA question as a final step of registration. I've been trying to define a boolean field which should have no widget selection dropdown or edit / delete operations within the "Manage fields" section for users.

It seems that the best way to define the field would be during hook_enable or hook_field_schema (inside your .install file), but I'm confused as to what the best practise is.

Also, is there anyway to give the database table a better name when defining your field? I find the table prefix for fields "field_data_xx" pretty confusing if you're defining numerous custom fields.

Thanks in advance :)

1 Answer 1


Q1: The field should be added in hook_enable() and removed in hook_disable() if you want the field to be removed and then added when you enable/disable the module. However I suggest implementing it in hook_install() and hook_uninstall as that will only remove the field and its data from the user entity when the module is uninstalled as oppose to simply disabled. hook_field_schema is not for these kinds of tasks as it's for defining a database table.

Q2: You'd have to hack your way through the field.module to make these database table name changes. This is really bad practice (VERY VERY) and plus I don't see the point of this, or never even heard anyone attempting this. The database tables are for Drupal and not for human eyes. As such they're in a consistent and systematic naming conventions so the field module as well as other modules that use them can easily extract data.

  • thanks for your response. Makes sense regarding the database table names, guess I was just being fussy :) Commented Jul 4, 2013 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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