9

I am trying to figure out how nodes are mapped back to the fields they contain for learning purposes. How is this done?

2 Answers 2

9

In Drupal 7 you have entities and fields; fields are attached to entities. A node is an implementation of an entity (the node module implements hook_entity_info() and other such hooks) so it can have fields.

All field/entity relational data is stored in the tables field_data_field_x and field_revision_field_x or similar (the latter potentially storing revisions of field data if node revisions are enabled).

The entity_id column in those tables is the node's ID, and the bundle is the node's content type. The revision_id is the revision ID of the node, again only really useful if node revisions are enabled.

UPDATE

In Drupal terminology a content type is a bundle and bundles are attached to entities (in this case the node entity). When you create a new content type it gets stored in the node_type table, and when the caches are cleared (which invokes hook_entity_info on all modules) the node_entity_info() function builds up a list of bundles from the content types (have a look at the bit in that function that starts foreach (node_type_get_names() as $type => $name) {, node_type_get_names gets a list of all content types).

As discussed above fields can be attached to entities, so fields can be attached to nodes with a delta (if you like) of bundle.

5
  • How does a content type that gets created in the GUI implement hook_entity_info? I understand how the field data gets stored, but how does the form get created? Oct 14, 2011 at 20:25
  • 1
    Is it field_config_instance that defines which fields go with what? Oct 14, 2011 at 20:34
  • @ChrisMuench: I've updated the answer let me know if you need any clarification it's quite complicated if you haven't delved around inside the core modules before!
    – Clive
    Oct 14, 2011 at 20:36
  • Oh sorry I got the wrong end of the stick I think, yes field_config_instance is literally where the field and entity type/bundles are related
    – Clive
    Oct 14, 2011 at 20:37
  • 4
    Minor addition. The field storage is pluggable, the field_data and field_revision tables are just the default implementation which is provided by field_storage.module. Other implementations for example allow to store field data in MongoDB.
    – Berdir
    Oct 15, 2011 at 9:08
0

In D7, for my case field_config_instance table provided me the required info.

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.