Skip to main content
2 of 2
added 384 characters in body
tenken
  • 18.4k
  • 2
  • 39
  • 57

Fields are attached to Entities, not Nodes. So the field is either attached to bundle that is your node (for all nodes, pre-existing or not), or it hasnt been attached to that bundle yet.

You can use field_info_field and look at the element bundles to see if your given field is attached to the given Entity. If it isn't you can use field_create_instance to add the field to your entity.

You can get a list of all entity types and inspect their bundle types with the bundles key returned from entity_get_info by calling $site_entity_list = entity_get_info(NULL).

Entities and fields are cached, so be sure you use something like drush cc all to be sure you're looking at up-to-date values for all these function calls.

EDIT: You use these functions and PHP from essentially a small php script. Such business logic could be in a small module with hook_update_n() for instance. Or, you could use Drush and write a very simple PHP snippet using hte above 3 functions and some loops and call it using drush like: drush php-script your-script-filename.php

tenken
  • 18.4k
  • 2
  • 39
  • 57