Hi there, First, these examples have seriously helped me at nearly every step of my big project. next, If I missed this (the solution to my query) somewhere else I apologize, but I am very confused as to how one might create an update, for example, if you build a node module, and then after it is out in the wild, you need to add an additional field to the nodetype.
My feature request would be a node_example update to answer the question:
how does one go about creating a deployable update if you created your node using the technique in this example
.
I created my node type, using the following in the .install file:
field_info_instance
field_create_field
hook_installed_fields
hook_installed_instances
and these in my .module file:
hook_node_info
hook_form
This is not exactly like the node example, but very similar. Anyhow, I now find myself scratching my head on how to deply and update to add a field to this complex content type that is already in use by users.
Thanks for all the hard work on these examples! and any help in advance :)
Franco Nogarin
Comments
Comment #1
alberto56 commentedIt would be a plus to demonstrate upgrading and updating. I have started a discussion on this in #1699440: A dedicated to module to demonstrate hook_update_N() and automatically testing upgrades and updates
Comment #2
mile23hook_installed_fields() and hook_installed_instances() are part of the EntityAPI API, as opposed to the Entity API. :-)
That is, not the core entity API, but the contrib Entity API.
But yah, an example of how to add/remove fields during an update would be great.
Comment #3
amphioxus commentedThis would be extremely helpful to me as well. After searching for a while, I still haven't come up with a way of doing exactly what you're trying to do. Uninstalling and re-installing with the extra fields is out of the question for me, because there's just too much data already there. Did you find any information to help you with your quest?
Edit: I think I figured out how to add a simple field to my already existing node. (I got my code mostly from this comment.) Since I don't need to update any existing nodes, there's no $sandbox for multipass updating. Not sure whether I'm following best practices, but here's my code (in the module's install file) in case it helps someone:
Comment #4
mile23Before you attach, you'd really also want to check that the node type exists, with node_type_get_type().
Then check that the field isn't already attached with field_info_instance(). Also use this function to verify that it's been attached after you attach it.
We really should have an example module for attaching and removing fields. Then people could just copy those techniques into their updates.
Any volunteers to write it? :-)
Comment #5
mile23Hmm. As it turns out, it was me.
Node Example shows you how, in node_example_node_type_insert(): http://drupalcode.org/project/examples.git/blob/HEAD:/node_example/node_...
It would be great if someone wanted to finish the job and incorporate this into an update/upgrade process, with tests.
Comment #6
mile23I'm going to call this fixed, because node_example_node_type_insert() shows us how to add fields.