programatically adding a CCK field to a content type.
Hi, I wanted to add an imagefield to a content type, using the function content_field_instance_create(). I wrote this piece of code. $field['field_name'] = 'myfield'; $field['type_name'] = 'story'; $field['type'] = 'filefield'; $field['widget_type'] = 'imagefield_widget'; module_load_include('inc', 'content', 'includes/content.crud'); content_field_instance_create($field); This works perfectly fine with me, and an imagefield gets added to the content type. are there any pitfalls in this i should take care of? or is there any better way to do such a thing? Thanks, -- Regards, Nitin Kumar Gupta http://publicmind.in/blog/
On Mon, Sep 21, 2009 at 6:51 AM, nitin gupta <nitingupta.iitg@gmail.com> wrote:
Hi, I wanted to add an imagefield to a content type, using the function content_field_instance_create(). I wrote this piece of code. $field['field_name'] = 'myfield'; $field['type_name'] = 'story'; $field['type'] = 'filefield'; $field['widget_type'] = 'imagefield_widget'; module_load_include('inc', 'content', 'includes/content.crud'); content_field_instance_create($field); This works perfectly fine with me, and an imagefield gets added to the content type. are there any pitfalls in this i should take care of? or is there any better way to do such a thing?
That's basically the approach I've been using for over a year: http://drewish.com/content/2008/07/programatically_creating_a_cck_field_in_d... The only complications I ran into with this approach was when you added fields in hook_install() and need to ensure field modules are installed: http://drewish.com/content/2009/06/creating_a_cck_field_in_hook_install andrew
This has worked for me as well, and I haven't had any issues. Testing with install/uninstall is important as is considering that that CCK field name might already exist. On Mon, Sep 21, 2009 at 3:51 AM, nitin gupta <nitingupta.iitg@gmail.com>wrote:
Hi, I wanted to add an imagefield to a content type, using the function content_field_instance_create(). I wrote this piece of code. $field['field_name'] = 'myfield'; $field['type_name'] = 'story'; $field['type'] = 'filefield'; $field['widget_type'] = 'imagefield_widget'; module_load_include('inc', 'content', 'includes/content.crud'); content_field_instance_create($field);
This works perfectly fine with me, and an imagefield gets added to the content type. are there any pitfalls in this i should take care of? or is there any better way to do such a thing?
Thanks,
-- Regards, Nitin Kumar Gupta http://publicmind.in/blog/
Can you please post the code to do such validations about other modules and field being exisiting already, so that I don have to re-invent the wheel. Thanks.. -- Regards, Nitin Kumar Gupta http://publicmind.in/blog/ On Mon, Sep 21, 2009 at 11:50 PM, Emma Irwin <emma.irwin@gmail.com> wrote:
This has worked for me as well, and I haven't had any issues. Testing with install/uninstall is important as is considering that that CCK field name might already exist.
On Mon, Sep 21, 2009 at 3:51 AM, nitin gupta <nitingupta.iitg@gmail.com>wrote:
Hi, I wanted to add an imagefield to a content type, using the function content_field_instance_create(). I wrote this piece of code. $field['field_name'] = 'myfield'; $field['type_name'] = 'story'; $field['type'] = 'filefield'; $field['widget_type'] = 'imagefield_widget'; module_load_include('inc', 'content', 'includes/content.crud'); content_field_instance_create($field);
This works perfectly fine with me, and an imagefield gets added to the content type. are there any pitfalls in this i should take care of? or is there any better way to do such a thing?
Thanks,
-- Regards, Nitin Kumar Gupta http://publicmind.in/blog/
One more thing, I haven't checked this out yet, but how do you delete the field that's created or update it? -- Regards, Nitin Kumar Gupta http://publicmind.in/blog/ On Mon, Sep 21, 2009 at 11:58 PM, nitin gupta <nitingupta.iitg@gmail.com>wrote:
Can you please post the code to do such validations about other modules and field being exisiting already, so that I don have to re-invent the wheel. Thanks..
-- Regards, Nitin Kumar Gupta http://publicmind.in/blog/
On Mon, Sep 21, 2009 at 11:50 PM, Emma Irwin <emma.irwin@gmail.com> wrote:
This has worked for me as well, and I haven't had any issues. Testing with install/uninstall is important as is considering that that CCK field name might already exist.
On Mon, Sep 21, 2009 at 3:51 AM, nitin gupta <nitingupta.iitg@gmail.com>wrote:
Hi, I wanted to add an imagefield to a content type, using the function content_field_instance_create(). I wrote this piece of code. $field['field_name'] = 'myfield'; $field['type_name'] = 'story'; $field['type'] = 'filefield'; $field['widget_type'] = 'imagefield_widget'; module_load_include('inc', 'content', 'includes/content.crud'); content_field_instance_create($field);
This works perfectly fine with me, and an imagefield gets added to the content type. are there any pitfalls in this i should take care of? or is there any better way to do such a thing?
Thanks,
-- Regards, Nitin Kumar Gupta http://publicmind.in/blog/
participants (3)
-
andrew morton -
Emma Irwin -
nitin gupta