I'm in the process of writing a module that will essentially publish a node to two sites (the one the user is creating the node on and another one specified in code). Both sites run on the same Drupal installation, with all the needed database info defined in $databases
.
In short, part of the process involves populating a hidden field in the second website's "article" content type. That field isn't defined on the first site because it doesn't need to be referred to there. I want to make Drupal "aware" of the field by the time it performs node_save(), but without actually creating the field on the first site, because the resulting tables in the database would go unused.
So, the basic logic of my module's code is:
- Modify the node form slightly to include a new checkbox
- If it's checked:
- Manipulate
$node
to specify values for a field that only exists on the other site - Use
hook_node_insert
andhook_node_update
to switch to the other site's database and perform anode_save
in it
- Manipulate
It's a bit more complex than that and the other site also checks said field's value to display a message, but the steps above are the ones relevant to my problem. Initially I thought just adding an array for the field in $node
would do the trick, but then I learned that the field needs to have an instance attached to the bundle before any subsequent database interactions will do anything with it. In order to do that, it looks like the standard procedure is to use field_create_field
and field_create_instance
- only I would like to get away with only using the latter, since I don't want the field to actually exist on the first site, only the second one.
Are there any reliable ways of achieving this? I hope I explained it well enough but will try to provide more detail if necessary.