Creating fields: custom vs. CCK
I need to create a new content type with about 20 fields. Should I use CCK or a .install file? The case for .install: "We'll first show you the programmatic solution by writing a module that uses Drupal hooks. This approach allows for a greater degree of control and flexibility when defining what the node can and can't do." -- Westgate and VanDyk, Pro Drupal Development (Google Books) The case for CCK: The New York Observer -- http://drupal.org/node/141187 CCK & Date/Link/Calendar/Imagefield/Imagecache. This site features a whopping 110 CCK fields. CCK has arrived, and helps us build sites quickly, and change them easily. -- Moshe Weitzman I will create custom forms with custom validation to refer to these fields, preferably from a .module rather than a PHP filter. In that case, won't I need to refer to both programmatically (e.g. a #validate form element)? Thanks! Sean
Sean Wingert wrote:
I need to create a new content type with about 20 fields. Should I use CCK or a .install file?
Most prefer cck fields because of the built in third party support for things like views fields, etc. But the overhead of the abstraction should be considered if the transactions speed is the utmost concern. In many cases though id rather go CCK + validation modules over custom because hardware is cheap and code is expensive to maintain and update. The programmatic creation of content types and fields is an area i would like to explore and develop personally. I would like to create "meta modules that provide these validation functions and automatically create required content types and fields for proper operation and deployment with minimal user interaction. Others working in these areas? Or existing functionality i dont know about? SoC, etc? -- Michael Favia michael@favias.org tel. 512.585.5650 http://michael.favias.org
First off I think you are comparing CCK to a custom module (.module). I would start by looking at CCK and see if it will meet your needs. If it falls short there are some alternatives to implementing a complete custom content type with a module. If you just need additional validation you can write a module that implement hook_nodeapi and adds validation to a content type created with CCK. Another approach I have used where I need more than custom validation is to use a module to provide the skeleton for a new content type (title, body plus and "special" fields I care about) and include any special logic I might need and then use CCK to add additional fields as needed.
With 20 different fields, it's difficult for users to input all 20 fields in one form. I want to separate the input into multiple tabs (MENU_LOCAL_TASK), each requesting a maximum of 5 fields of input. Unlike a multi-step / wizard-style form however, the data can be input in any order and not all fields are required, so the tabs (hopefully) help with data input and navigation. However, this creates problems: (1) need for multiple forms, (2) each form touches (validating, INSERT, UPDATE) different fields. It seems that CCK does *not* require programming for the addition / deletion of fields, but the validation (e.g. regexp) of those fields *does* requires programming (via a PHP filter or a .module). Is that correct?
"I would start by looking at CCK and see if it will meet your needs." With CCK in my scenario, creating fields still requires validation (thus programming?), and while validation can be done via a PHP filter, an admin who accidentally deletes a field deletes the corresponding validation, whereas in a .module, the same admin would not have deleted the validation.
"Another approach I have used where I need more than custom validation is to use a module to provide the skeleton for a new content type (title, body plus and "special" fields I care about) and include any special logic I might need and then use CCK to add additional fields as needed." I like this, but for validation, it seems like I'll need to write a .module to access (e.g. INSERT, UPDATE) the CCK field names (field_something) from the content_type table(s).
"If you just need additional validation you can write a module that implement hook_nodeapi and adds validation to a content type created with CCK." This seems like a hybrid of CCK with a .module, which also seems(?) expensive, since drupal fires it off whenever it sees *any* node type? ("The nodeapi () hook is usually called by the node.module just after the node type-specific callback is invoked." VanDyk and Westgate).
What do you think? Sean
On 31 Mar 2008, at 7:26 PM, Sean Wingert wrote:
"We'll first show you the programmatic solution by writing a module that uses Drupal hooks. This approach allows for a greater degree of control and flexibility when defining what the node can and can't do." -- Westgate and VanDyk, Pro Drupal Development (Google Books)
As I was programmatically creating fields, it ended up being quicker and easier for me to write them as custom modules, since i really was only using cck to get away from writing 2 form fields (edit and view) and 3 sql statements (insert, update and delete). The only thing that was moderately tricky was learning how to support views completely in my custom types. Also, all my code is versioned and has a code based upgrade path, whereas cck1 is just not built for that kind of thing. I was also writing a lot of back end integration code, and my code quality was a lot better not having to litter everything with $node-
field_some_thing[0]['value'] instead of node->some_thing.
Also. custom node types can still be extended by cck.
participants (4)
-
Adrian Rossouw -
Michael Favia -
Sean Wingert -
Steve Ringwood