I've been looking for an anwser to this question: what is the reason that would make a developer to choose to write his own module instead of using cck? I haven't used cck much, yet, but I guess it's very powerfull, although writting your own module would give you full control of it. However, what's the point to go for an own module? Is there an exact answer to this? What is the exact limitation you have by using cck? Have anyone else thought on this matter and came up with a clear decision?

Comments

Chill35’s picture

If you want to create a content type that is just like a story or just like a page or just like a blog, then creating a content type module is very easy. It is as easy as copying, for example, the file story.module, renaming it to {your-content-type}.module and doing a find and replace with "story" and {your-content-type} MORE or LESS in that file.

As a newbie I was able to create a new content type called short_story in about 5 minutes, by creating a module.

I didn't like CCK because it displays a title for each field and the textarea field wasn't flexible enough for me.

However CCK is useful when you want an assortment of different fields for a content, one being an integer, another a phrase, another a date, another text, etc.

Caroline

Chill35’s picture

A lot of people use contemplate along with CCK. And if I had used that other module I would have been able to get rid of the field titles :

This module was written to solve a need with the Content Construction Kit (CCK), where it had a tendency toward outputting content in a not-very-pretty way. And as such, it dovetails nicely with CCK, adding a "template" tab to CCK content-type editing pages and pre-populating the templates with CCK's default layout. This makes it easy to rearrange fields, output different fields for teaser and body, remove the field title headers, output fields wrapped for use with tabs.module (part of JSTools), or anything you need.

From http://drupal.org/project/contemplate

I was looking for an extra content type that was just like story and page, so I went ahead and created a module based on story.module.

Caroline

hazamonzo’s picture

robertgarrigos, I understand what you are saying as its something i think about all the time. Developing your own (relatively complex) module isn't an easy task as i have found out. It isn't that drupal doesnt support custom module development well, its just that getting all the information and especially tutorials is very hard. I spend alot of time trying to understand the ins and outs of drupal by browsing through all the drupal hooks in the API documentation but alas it is a difficult task. If however you are looking for basic fast creation of node and such, the CCK module is fantastic! For me however its lack the ability to really create something special. As far as i know when you create custom node types in the CCK and you want these nodes to relate to other nodes, you can only achieve a 1-1 and 1-N relation. I on the other hand want to create a module that supports a n-n relation in my table. I havent figured out how to do this just yet but for me it means creating a custom module.

Feedback is appreciated

robertgarrigos’s picture

As far as i know when you create custom node types in the CCK and you want these nodes to relate to other nodes, you can only achieve a 1-1 and 1-N relation.

That's exactly the type of anwser I was looking for :-)

Besides all other good points expressed here about module's independency (dublindrupaler), which I might consider at some point - the type of clients we have here in Spain are those that ask you how they can bypass iexplorer's cache, so no way to ask them to administer their cck module :-) - , I was wondering what are the technical limitations of cck. This is, those limitations that would force you to write your own module. Are any other ones? How about theming?

BTW: any experiences on combining your own module with a cck solution?

---
Robert Garrigos

coreb’s picture

From what I've heard, the blog node type in 5.x core is actually created from CCK calls in node.module. But I'm not 100% on that.

I don't know if that's what you wanted, but it's a quick example.

pearcec’s picture

As far as i know when you create custom node types in the CCK and you want these nodes to relate to other nodes, you can only achieve a 1-1 and 1-N relation.

Does anyone have examples of this?

yasheshb’s picture

hazamonzo:

in case the api's and the tutorials are hard to use, there's an excellent book on drupal
pro drupal development - jon vandyk/matt westgate.

i've used it and found it a great resource while coding drupal modules. hth.

yashesh bhatia

----------------------------------------------------------
Go Pre
http://www2.localaccess.com/rlalonde/pre.htm
----------------------------------------------------------

Yashesh Bhatia

Dublin Drupaller’s picture

Hi Robert,

Interesting topic..

I pondered the same question recently, i.e. what is the reason that would make a developer to choose to write his own module instead of using cck?.

The conclusion I came to is that it's far better to run with CCK rather than develop your own modules.

The main reason was because I tend to develop for other people on contract and a key factor during the handover stage of a Drupal project is that the project is independent of me.

In other words, if I created custom modules, instead of using CCK, the project owner is really tied to coming back to me for updates/ammendments/improvements/upgrades. Where as if I used well-support modules, it's much easier for them to D.I.Y. changes or find another Drupaller to tweak it for them.

It's not impossible for them to find a Drupaller that can dive into someone else's code, but, invariably, especially with tight deadlines and creating custom modules, there is bound to be something unusual that can confuse another Drupaller. Let's face it, when most are creating/tweaking modules for themselves, many don't comment and document for themselves as they go along. So while it's not impossible to jump in to someone else's code, I would tend to try and stick with Drupal core with well supported modules instead.

Another, bigger picture, factor is that it keeps the patch/updates alive on drupal.org. i.e. If it was encouraged to create a custom module for every new variation required by a client, the patch que would be empty, modules would never improve and the real value chain Drupal offers falls down.

The only negative aspect I considered was the memory factor...i.e. it maybe more memory efficient to use slim and trim custom modules rather than the cck suite and add-ons. Having said that, I have worked on some music sites that had huge peaks in traffic and using cck.modules didn't hinder that at all. There wouldn't have been much value in using custom modules instead.

The handover aspect overrides all the possible values in saving a bit of memory. Consider how much smoother it is for a client, using cck rather than custom modules, to upgrade their site when a security announcement flies into their email box or if they, for example, want to enjoy some of the new version features?

That's just my 0.02 cents......

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

AjK’s picture

For me, the choice between CCK and a module is simple. As DD said above, if you need an "independent" setup, CCK is the way to go.

But I'll give some more thoughts.

Out of the box, CCK (and then plug in the Views module) gives end users a great deal of power without having to know any PHP or MySQL. And that's what they are designed to offer. For the most part, this combination works fine.

However, there is one area where realistically, only a module will do. We all have them. It's client that comes back wanting more and more features as their site grows (and are prepared to pay for it!). An example, custom searching. If you know your own module inside out then extending it and adding extra functionality is a breeze. With a CCK+Views deployment you have to start getting into the db construct for the site. If you want it generic across sites, you have a lot of settings admin work to do. Or hard code it for that site. Either way, it's sometimes a lot of work to retrofit custom work over CCK+Views.

So, my solution as to which way I jump is client driven. If it's "just another blog site" CCK+Views et al is the way to go. If you have a demandling client that wants change/feature creep a custom module I find better at "future support". It's all down to the application.

<edit>I should have added. CCK extends node types. If you need to do something that's not extending a node type then a module is your only soltion. So far, this thread has assumed all modules are node extensions. That's not always the case</edit>

Dublin Drupaller’s picture

I should have added. CCK extends node types. If you need to do something that's not extending a node type then a module is your only soltion. So far, this thread has assumed all modules are node extensions. That's not always the case

minor point and I maybe wrong about this, but, if you're not extending a node type, why would you create a module for that node type? Wouldn't it be better to use the out-of-the-box taxonomy.module to categorise and/or theme different variations of the node type?

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

AjK’s picture

There are things that Drupal doesn't get near or only close. For example, specialized searches, workflows that don't fit into the workflow module, etc. I'm not just talking about nodes. I'm currently writing a "Contacts directory" module that backends onto a totally foreign database. It has nothing to do with Drupal as such, the client just wants to have the data "visible on their site". The site's Drupal, hence a module. That's what I mean by "non-node type extensions". Things completely outside of "out of the box".

emdalton’s picture

I'm looking at trying to port the Invisimail module, which doesn't create a node or touch the taxonomy. I need this to protect email addresses which need to be displayed on our site. I think that's a good example of a function that needs its own module (though I strongly wish this was handled by Drupal core.)

brst t’s picture

The conclusion I came to is that it's far better to run with CCK rather than develop your own modules.

The main reason was because I tend to develop for other people on contract and a key factor during the handover stage of a Drupal project is that the project is independent of me.

In other words, if I created custom modules, instead of using CCK, the project owner is really tied to coming back to me for updates/ammendments/improvements/upgrades. Where as if I used well-support modules, it's much easier for them to D.I.Y. changes or find another Drupaller to tweak it for them.

It's not impossible for them to find a Drupaller that can dive into someone else's code, but, invariably, especially with tight deadlines and creating custom modules, there is bound to be something unusual that can confuse another Drupaller. Let's face it, when most are creating/tweaking modules for themselves, many don't comment and document for themselves as they go along. So while it's not impossible to jump in to someone else's code, I would tend to try and stick with Drupal core with well supported modules instead.

[..]

The handover aspect overrides all the possible values in saving a bit of memory. Consider how much smoother it is for a client, using cck rather than custom modules, to upgrade their site when a security announcement flies into their email box or if they, for example, want to enjoy some of the new version features?

Good points.

And it's also now easier to export/import custom CCK types and Views. Import and adjust to taste.

1kenthomas’s picture

The main reason was because I tend to develop for other people on contract and a key factor during the handover stage of a Drupal project is that the project is independent of me.

Worth repeating.

Cool_Goose’s picture

Well it's easy... CCK is a recent module and now it has been added in a simplified version in the core.
Some people prefer to keep their modules updated some discontinue them in favor of cck.

------------------------------------------------------
Be Smart, Think Free, Choose OpenSource.

hazamonzo’s picture

The points posted above a good ones but for me the real issue is how the CCK works. My aim with drupal is not aonly to use it as a cms but i am extremely interested in getting this stored information from the database and exporting it to third party applications (analysis applications to be precise). Now, if i create my own module i will have alot more control on how the module interacts/inserts data into my database but as i have found with CCK, this isnt so simple. The way i see it from a database structure view (and im sure not everybody will care) is that CCK makes it very hard to get at the data maybe using an ETL tool and exporting it elsewhere. This could be of course because of my lack of knowledge with the drupal database schema but i have never yet worked with such a hard structure. Anyone out there understand it better than i do? ;)

Best regards

coupet’s picture

Interesting topic, Drupal offers two(2) excellent options to create custom nodes:
- Custom modules
- CCK

I wish there was a table/chart that compare/score the options:
Database access(speed), Performance, Memory usage, Export/Import, Ease of Install, Ease of Use, Upgrade Path, etc.

----
Darly

druru’s picture

Lets say I create a bunch of CCK custom content types and it works great. The probelm comes when it's time to move those custom nodes with their configurations to a new site.

As a module, i pick up the module and enable it on the new site and i have all of my functionality. Cool.

However, if everything is done in CCK i'm fruked when it comes time to move that over to the new site. I'm going to have to manually type in all the configurations for those content types, field by field including configuring each field. What if i forget how to or just miss one step that i used to create the original the cck type? what if i've got 8 custom types with a range of 8 fields on each? What if they require other setups with other related modules?

The solution: A hybrid module:

Here's the challenge.

Does anybody know how to create a small custom module that will basically programatically create the CCK content types you create manually by hand!?

vm’s picture

an interesting article with some interesting responses on this topic can be found here: http://www.nicklewis.org/node/885

Phillip Mc’s picture

Hi verymisunderstood,

I saw that article a while back and I don't think it is very accurate.

For starters, Nick Lewis's number #1 reason for not using CCK is because a lot of node hooks are lost. That's actually not true as anyone who has used the module will tell you.

His comment to only use CCK "if you won't need to do anything special with the nodes" is an interesting idea. I would argue that if you don't need to do anything special with the nodes, you shouldn't need the cck.module or custom modules in the first place.

My two cents on the matter is that it's far better to base the cck v. custom module decision on the core concepts behind Drupal. The cck.module fits very snugly with the core concept of modular group development. Creating custom modules for new node types doesn't IMHO.

Apart from some inaccuracies in the article, which may have something to do with when it was written (october 2006), the main reason I would disagree with Nick Lewis's approach is because a Drupal site is never finished.

A Drupal site is always evolving and when you're creating a custom node module you're relying on just 1 developer. i.e. You. As opposed to the large number of developers who have contributed and continue to contribute to the CCK and add on modules.

Consider if Nick Lewis has 12 websites, with an average of 6 custom node modules on each. All with varying degrees of customisation. That's 72 modules that need chekcing/updating.

That's a bit of a headache compared with 12 Drupal websites, built with the cck.module, with 6 custom node types. i.e. only 1 module and maybe a few other add-on modules need updating.

It's not just the updating that is the problem. It's ideas as well.

One of the spin-off benefits of modular group development is ideas. I often find myself spotting a new module addition on Drupal.org and going back to a client and suggesting it might work for his/her project. If you're working with custom node modules, you can still use the ideas, but, they are harder to implement than just downloading an add-on contribution for cck.module and enabling it.

There are some good points made in the article, but, I think it needs revisiting and wouldn't recommend it to any newbies wondering about the pros and cons of using cck versus custom node modules. the CKK. module has moved on a lot since that was writeen so a lot of what is being discussed there has already been covered or is in the process of being covered.

phil

vm’s picture

I linked to that page, not specifically for Nick Lewis's article, but for the comments made by others in the article. Thus despite Mr. Lewis's comments in the article itself. The discussion that insued in the comments after the article was published I thought pertained to this discussion. I personallly found the comments by other individuals more enlightening than article itself in most cases. The defense of CCK rather than the article about neutred nodes. I felt it presented both sides of an argument. There is also a podcast with KarenS in lullabot.com that deals with how CCK is evolving and such.

Chill35’s picture

A lot of contributed modules are implementing custom node types already.

E-commerce provides, for example, nodes that are "files to download that wil cost you money".

Quickfiles is a dedicated e-commerce-off-spring module that has "quickfiles" as nodes.

There's an image module (can never remember which one it is) that makes nodes out of images (IMCE ?).

And on.

I am now working on a module that makes "inspiration cards". It makes a fairly complicated use of the node form.
It has dedicated administrative pages.

To properly quote the "Neutered nodes" article from which the phrase "you won't need to do anything special with the nodes" was quoted out of context :

In general, I'd only recommend using CCK when:
1. The client being able to define their own content types is a top priority.
2. You don't need to alter the node forms.
3. You won't be needing to integrate the nodes into other modules.
4. And overall, you won't need to do anything special with the nodes.

Doing something special to nodes as in "do something that you cannot do with CCK", as I understand it.

In Drupal 5, here is my own root in making "special" nodes.

1. Use taxonomy. If that's not enough, go to 2.
2. Use the built-in-core custom node type creation functionality. If that's not enough, go to 3.
3. Use CCK or a contributed module that already deals with making similar nodes. If that's not enough, go to 4.
4. Create your own module.

Caroline
Who am I | Where are we
11 heavens

newdru’s picture

be making your inspiration module publicly available? I'd be interested to see how you coded it with CCK content types.

thanks

Chill35’s picture

I am not using CCK content types, no.

Caroline
Who am I | Where are we
11 heavens

Phillip Mc’s picture

I think you're confusing content with functionality Chill35. The quickfiles.module & ecommerce modules are functionality based, not 'node' based in the context of what a node is in Drupal.

As an example, the ecommerce module utilises hooks that latch onto nodes - including CCK nodes - that provides ecommerce functionality. The quickfiles.module doesn't treat quickfiles as 'nodes' - it treats them seperately as an uploaded file in a private folder on the server. In other words, both quickfiles/ecommerce modules are functionality driven..not content type driven.

In simplicity,

  • The product module allows *any* node to be treated with the ecommerce product functionality using Drupal hooks.
  • The quickfiles module *only* allows nodes created by the quickfiles module to have links to files that are treated with quickfile functionality.

Nick Lewis's number 1 argument for not using cck.module is that those node hooks don't work with cck. That's actually not true and I just thought I'd flag it because an earlier poster described it as an "interesting article" which might confuse others. There are some great comments to that article, but, the point I was making was the article was innacurate and probably simply out of date. If I was a newbie and saw a link to an "interesting article" like that, I think I would assume it's on the money.

For me, the cck.module is more of a CONTENT API. In a similar way to how the FORMS API has evolved into an incredibly powerful piece of kit the CCK module is heading in the same direction.

I'm not sure if I'm explaining this properly but, as another example, you are creating a module that introduces "inspiration card" functionality into a Drupal site.

There are essentially 2 approaches to doing that:

(a) create a new module that uses it's own new content type.

(b) Use existing Drupal hooks (ala ecommerce and many other modules) to allow users to apply 'inspiration card' functionality to *all* node types.

The quickfiles.module was made using approach (a) and the author is very aware that he's replicating a lot of what already exists with the ecommerce.modules and in particular the file.module.

While I'm not saying approach (a) is wrong...the quickfiles.module is a great module..but, when you look at the bigger picture, won't your 'inspiration card' module be infinitely more useful if it was developed using approach (b) where users can apply 'inspiration card' functionality to video, audio, cck or any node types.

In the same way, the quickfiles.module would be even more useful if it was an add on to the ecommerce suite, rather than a stand alone module. e.g. *all* the payment gateways already created for ecommerce would also work with the quickfiles.module instead of the module maintainer having to replicate that code/functionality.

There's also the question about how the memory load on a Drupal site increases with the more code (modules) that's loaded. By using hooks, there is less replication of code and they are "lighter" and more efficient from a memory perspective.

The bottom line, I suppose is all about about content versus functionality. Instead of Nick Lews's question of whether "you want to do anything special with the nodes", it might be more correct to ask "is there something you want to do *to* the nodes that you can't do using taxonomy/theming?"

That leads you down the path of custom module creation and when you get to that stage, it's probably smarter to follow the ecommerce product.module approach- where the functionality you are coding can be applied to *all* node types using hooks, rather than simply copying/replicating existing code and
adding on to it.

Phil

Chill35’s picture

The quickfiles.module doesn't treat quickfiles as 'nodes'.

Are you sure of what you're saying here? A quickfile is of content type 'quickfile'. It has a node id & all.

This is exactly what I am talking about here, Phil : functionality. I just make a different reading of Nick Lewis's article than you are.

I think that what Nick Lewis is saying is this : when you are beyond templating a custom node type, and are doing special things with the node (in terms of functionality), then you have to ask yourself : why not combine the custom type creation with the functionality that it goes with... in the same module. Why not ? You end up with one module instead of the CCK module plus a module that only deals with ONE CCK custom type node. What you are saying now is this (correct me if I am wrong) : the functionalily could be applied to other custom node types. Both in theory and in practice you are correct. But it's not always true, and not only that : to make your module bend backwards with the idea that some day some other guy with some other idea might want to use it is not always affordable, in terms of time and energy.

Quickfiles (while we are discussing them) are a particular case. I understand the need for such a module insofar as at the time it was put together : the e-commerce package was set against anonymous purchasing, which quickfiles allows. Also e-commerce is a huge thing (even when you enable just the the basic 3-4 modules to have it working). I had to dramatically increase my allocated php memory to have the e-commerce set of modules work on my own web site.

A newbie is not a newbie to the world - just to Drupal, and he can wade through the different opinions he reads and make his own decisions. A while or minutes after I believe that someone may not be as smart as I am, I am usually shown the opposite.

While I'm not saying approach (a) is wrong...the quickfiles.module is a great module..but, when you look at the bigger picture, won't your 'inspiration card' module be infinitely more useful if it was developed using approach (b) where users can apply 'inspiration card' functionality to video, audio, cck or any node types.

No. My module is such a special thing that it probably won't find its way in CVS. I will just use it on my web site, and document the process of making it. By the way, you don't know what my project is about. You know nothing about it. Not yet ;)

You would make a better argument with a module like the bookreviews.module. I can see this module as a good example to support what you're saying.

Nice talking to you. Thanks.

Caroline
Who am I | Where are we
11 heavens

yched’s picture

I'm going to have to manually type in all the configurations for those content types
Not true anymore for drupal 5 : content_copy.module inc cck 5 distro provides "à la Views" content types definitions import / export.

newdru’s picture

I didn't realize that existed.

yched, can i ask you another question while we're at it.

Is there a way to programitically create a cck content type in code?

For instance, say i want to create a custom module that for whatever reason depends on another cck custom node type. It would be great for my module to actually be able to create the child cck content type at install time so that the module can be self contained and not force the installer to go out and create the cck type by hand. i would imagine there might be a cck api for creating cck types from within a module. if not it might be very useful.

Is this possible?

thanks

newdru’s picture

The $content[type] array has all of the fields associated with my current content type INCLUDING NODEAPI FIELDS (e.g send module and fivestar module, etc).

1) When you paste the export into the import, does it recreate all of the nodeapi settings/fields on the new cck content type or just the base / core cck fields?

2) Can you just export / import one or x number of fields verus the whole type.. e.g. dup one cck field from one cck type to another one?

thanks much

coupet’s picture

Right solution is critical to project success.

CUSTOM NODE
---------------------
Provide a new node type to the system.
http://api.drupal.org/api/4.7/file/developer/hooks/node.php

The Drupal forms API allows for almost unlimited possibilities for custom theming, validation, and execution of forms.
http://api.drupal.org/api/HEAD/file/developer/topics/forms_api.html

CCK NODE
---------------
Modules: CCK
http://drupal.org/project/Modules/category/88

----
Darly

robertgarrigos’s picture

This is exactly what I'm looking for, as a developer. Who does it? ;-)

---
Robert Garrigos
Professional site: robert.garrigos.cat
Catalan Drupal Users Group: drupal.cat

jfall’s picture

I wish there was a table/chart that compare/score the options:
Database access(speed), Performance, Memory usage, Export/Import, Ease of Install, Ease of Use, Upgrade Path, etc.

This would be a very worthwhile thing to have....
and while we're at it, how about a comparison of Image.module vs. CCK Imagefield as a prime example of the trade-offs involved!!! (although I realize Image.module pre-dates CCK)
This one has caused me sleepless nights - one must choose one or the other as the standard for a site, but whichever choice, you lose something up! It'd be so nice if someone with more experience with these could layout exactly what is lost and what is gained by this choice.

xpereta’s picture

and refrain from creating full blown node modules unless necessary, regardless of whether the administrator will need manage the content fields on her own or not.

And if I need some extra functionality I usually create a module to define a new CCK field type instead of a new independent module. I have found it's easier for the developer and I can reuse functionality easier.

It depends on the extra functionality you need, though. I have found this approach works well when I want to show information that I must request from a web service based on a parameter that is the value of one of the fields of my node.

mlncn’s picture

Is any of this wholly custom node module development going on in Drupal 5? I would greatly appreciate pointers to the resources or base module people use.

And count Agaric Design in for any and all efforts to make programmatic CCK easier and the use of CCK extensions in custom modules, for two routes for the better of all possible worlds!

~ben

People Who Give a Damn :: http://pwgd.org/ :: Building the infrastructure of a network for everyone
Agaric Design Collective :: http://AgaricDesign.com/ :: Open Source Web Development

benjamin, Agaric

rjl’s picture

I had this same question recently...

I had written a few handbook pages about creating your own simple node type (4.6) and (4.7) - those used the "old" (pre 5.x) story module as a starting point, and showed people where to change the code in order to create their own simple node-type.

When Drupal 5.x came out with its new method for handling node types, I wasn't sure that creating an updated version would be needed or necessary. But, on upgrading a site recently, I realized that I needed some permissions functionality not offered by drupal core; specifically I needed a separate "View" and "Delete" permission for two node types. The only modules appearing to offer what I needed were the various "node access" modules, but frankly I didn't want the extra overhead, the permissions I needed were not node specific, but global to all nodes of the type.

I had originally created the site with 4.6. I created 2 node modules that had a lot of extra fields and the extra permissions, but other than that, they were pretty vanilla node-types. Sorry, I don't remember for sure why we didn't use flexi-node at the time. So with 5.x coming out, I decided we should upgrade, I didn't want to be too many versions behind. I was excited about it because I thought I would be able to convert the 2 custom node types to CCK node types, and have no custom modules in the site. The conversion took a while, figuring out all the INSERT query strings I needed, but worth it. (and if you want a how-to on that check this out.) Then I realized I didn't have the permissions I needed - Damn!

My initial reaction was to just upgrade the custom modules to 5.x - not the worse thing. But then it dawned on me, CCK adds fields to any node-type and that I could in theory create a "simple" node-type module that provided me with the extra permissions, but the additional fields could still be handled by CCK. So that is what I did. I guess you could call it a "hybrid" - it only has the minimal code needed to instantiate a node-type with slight alterations to hook_perm() and hook_access() to provide the fuctionality I needed.

Because I needed to know how to do it, (and some asked me to do it also) I created handbook a page How to create your own simple node type (5.x). It is written specifically for those new to drupal, but anyone who knows what they are doing can breeze right thru it, picking up what they need to know.

Island Usurper’s picture

The Übercart uses modules to create custom node types, specifically products, because it's easier to distribute a node type module than a script that sets up CCK node types with all the required fields. It is possible to do it that way. The latest release uses the Image field and image cache to store product images, so they needed to be enabled automatically. I can't expect everybody who downloads Übercart to set up image fields the same way as everyone else no matter how good the instructions are. This also ensures that people are using the exact same product module, barring their own customizations.

I think the answer to the original question involves the number of sites that are going to use the new node type, and the complexity of functionality. If all the node is supposed to do is contain content, then CCK is great. If it's a one-time thing for a specific site, CCK is great. If the node has to interact with various and sundry other modules in and of itself (products added to a shopping cart, selectable attributes, etc.) then CCK doesn't work and you need a custom module.

This, I think, is the main difference. CCK is what you need when nodes don't have to do anything.

Modules also allow you to package together non-node functionality in with the node type. Every kind of hook can be implemented in a single module: custom blocks, user interaction, taxonomy. For a single site, you can do all of these things separately, even if their related in some way. But the next time someone wants a very similar thing, you have to make everything from scratch again. With a module, you just plug it in and teach them how to use it.

-----
Übercart -- One cart to rule them all.

nevets’s picture

Regarding "If the node has to interact with various and sundry other modules in and of itself (products added to a shopping cart, selectable attributes, etc.) then CCK doesn't work and you need a custom module.", with 5.0 I would disagree somewhat as you can now combine the best of both worlds. I recently worked on a project where I cared about the behaviour of the content but not the actual content. So I ended up writing a custom module with a bare bones content type and then used CCK to add the actual fields/data.

druru’s picture

Say a little more about how you got the functionality in your module to "act" on the CCK fields that you added to the content type later? I mean how do you access the cck fields from within a module that the fields get "attached" to? what is the hook and or object/array syntax to access/manipulate the fields.

That sounds odd to me. Kind of like chicken before the egg :-)

nevets’s picture

The actions of the module are independent of the data so it does not care about the CCK fields.

Island Usurper’s picture

Exactly. The data that the module needs to be present so it can act upon it should be defined in the module, but CCK can add anything else on it's own.

-----
Übercart -- One cart to rule them all.

mcurry’s picture

This is the main reason I'm not jumping up and down about CCK - it's incredibly useful, based on what I've done with it - but I need dead-simple drop-in distribution and installation on other Drupal sites, and I can't see that it's here yet. (Please correct me if I'm wrong!)

If I create a complex application using CCK and CCK fields, how do I package that up for drop-in installation on three other sites? Sorry, jumping through configuration screens and clicking forms is not going to happen. (Again, please tell me if I'm wrong, how can I package up CCK applications for plug-and-play distribution to multiple other sites? The macro stuff I've read about in the past seems too 'Rube Goldberg'-ish for my tastes.)

I've found similar issues with Views - powerful, but not quite there yet when it comes to multi-site deployment (export/import) - dependencies on a variety of site-specific items such as taxonomy terms... (and yes, I rely quite heavily on Views, it's great! I'm sure I'll say the same for CCK soon, despite my current misgivings.)

While I see that work is being done in this area, as far as I know, it's not there yet. I don't know enough about CCK to help in this effort, unfortunately, and I need to complete my tasks rather than invest the time in learning about CCK and related module internals - I plan on diving in to CCK after I deploy my current projects.

But I do see that the CCK system will be a key component of Drupal - it's very sexy and stealthy - when CCK is fully baked, Drupal will be a much more powerful platform and hard to beat for most applications.

Michael Curry - http://exodusdev.com

nevets’s picture

You can export and import CCK types so there is no need to redefine a content type. This works for both content types completely defined with the administrative interface and even for fields added to existing content types. I used this ability in developing a site, defined things on my test machine then when ready export the definitions and imported on the "live" site (in test at the time).

druru’s picture

can you say more about how you dynamically created the cck image fields attached to the product node type in your product module?

What hook is used to create the cck fields?

Is this done in the module or the install file (since it only needs to be done once)?

thanks

druru’s picture

CCK for reuse is definitely better with content copy (import/export) but i agree a standalone module is still ultimately more powerful. CCK is easy to implement though so that is a plus!

My concern though is runtime speed. CCK uses a lot of extra tables and each field is supported by a separate module. From what i understand, each active module is loaded or at least parsed for every nodeapi call. And regardless of nodeapi, cck still has lots of different modules performing lots of different things for all the field plugins and probably more to tie everything together.

I can't prove this or really have a way of quantifying it, but it would seem that a self contained module that can perform most of what it needs from within it's own module codebase has got to be a lot faster period!

Drupal's power is the flexibility that comes from it's plugin architecture with nodeapi and themes and blocks etc... That power and flexibility comes at a cost though because every page has to line up a series of callbacks beforer that page can be created and every node load is going to check every single active module for the presence of hooks at just about every operation. Again, that's required to allow the extensibility via the module architecture but it slows things down.

Just wonder if others actually take these things into consideration. I've found that running sites on my localhost (no network involved) often run slower than they should. I'm wondering how they're going to perform live on the net!

Island Usurper’s picture

Drupal is very good about caching frequently used data and using static variables to hold things in memory instead of getting them off the disk for every function call.

From what I've seen, whenever a Drupal change is loaded, all the enabled module files are loaded into memory. This means that all the functions are in the namespace already. Whenever module_invoke_all() is first called for a hook, it constructs an array of all the functions that implement it which persists for the rest of the page's life. Every subsequent time the hook is invoked for all modules, all that happens is that the appropriate key from the array is retrieved, and the function is called.

While CCK is certainly doing quite a bit of complicated stuff with callbacks and dynamic tables, plenty of smart people have already done considerable work in keeping redundant processing from bogging down the processor.

-----
Übercart -- One cart to rule them all.

lucyconnuk’s picture

I've been looking at CCK vs. custom module for a site where I have several content types which relate to each other, and I want to have a particular page which shows related fields from more than one content type.

e.g. I have a Venue content type (with Name, Address, Website Address fields) and an Event content type (with Event Title and Date fields and using a node-reference field to indicate Venue). I want a page which lists Events, but which also includes the Web Address of the Venue.

I thought it would be easiest to create my different content types with CCK, and then write a custom module to create the page.

This was very easy to write and worked fine - UNTIL I then defined another content type which also used the Web Address field. This caused CCK to move the Web Address field from the content_type_event table into its own table called content_field_web_address. OK, that's fine - that's how CCK works. But it means that the SQL queries in my custom module are now all wrong!

So in other words, I have lost the easy expandability of CCK, because whenever I add another content type (or, presumably change or remove one), I'm in danger of messing up my custom module.

Is there any kind of API to CCK that allows you to make SQL queries without having to know exactly where CCK is storing a particular field?

Lucy C

mooffie’s picture

I thought it would be easiest to create my different content types with CCK, and then write a custom module to create the page.

Or you can use Views to generate the listings. But I guess you already know that.

Is there any kind of API to CCK that allows you to make SQL queries without having to know exactly where CCK is storing a particular field?

There's a function, content_fields(), that tells you in which table the field resides. You can use SQL table aliasing to make your SQL work no matter where the field is stored: whether in the main content-type table or in a stand-alone table.

Let's say you have a field, field_age, and you want to find all the nodes having field_age_value > 21. You can do:

$field = content_fields('field_age');

$db_info = content_database_info($field);
// db_info['table'] now tells us where's the field

$sql = "SELECT
          n.nid, n.title, a.field_age_value
        FROM
          {node} n
        INNER JOIN
          {". $db_info['table'] ."} a ON a.vid = n.vid
        WHERE
          a.field_age_value > 21";

Other approaches:

- You can use Views. You can create and manipulate a 'view' object through code. You can also use View's query object.
- You may find calling content_field() directly useful.
- Well... you can add your field to a dummy content-type to make sure it always resides in its own table. OTOH, having to do all these JOINs isn't as efficient as not doing them.

lucyconnuk’s picture

Wow, Mooffie, that's exactly what I needed. Thanks very much!

Lucy C

mooffie’s picture

There's a function, content_fields(), that tells you in which table the field resides.

Oops. I have a little mistake here, of course: I meant content_database_info(), not content_fields() (you use the latter to grab a Field Object, which you pass to the former).

rleddy’s picture

Just a few days ago, I put more info about ROLLED OATS out there.

OK, this is my module, and it's time for debugging. This module may actually be a replacement for CCK on one level, while some backend parsimony may be applied to data bodies that the form delivers.

I find that by switching to using the OAT package, or perhaps some other javascript toolkit, much of the input type validation can be done at the client. And many of the fields can be placed in the one body field of the form. Further, I can begin to create a repository of fields that are stored in a DB and rendered as JS and HTML components.So, the forms go to the DB and server much less.

Some validation of data requires a server. But, with AJAX, there is no need to involve Drupal in quering up services such as credit card lookup, unless of couse you want to. The result has to go back to the form as validated or not prior to the final form submission (or POST or GET). Javascript is designed to stop the faulty form from going. Furthermore, Javascript with it's AJAX part, can delay the form submission until secondary server validations have completed their asynchronous call backs. So, there is no need to embed these queries into a custom field handler that goes along with custom field tables, etc.

Here is another interesting feature of the ROLLED OAT. I found that by using the repository of OATS, and the OAT kit from openlink, I had less code required to handle the interactions with the fields and the Data. So, now I about as much of the functionality I want for taxonomy form field management with just a little bit of code. So, by taking a different approach to handling the data and the form management, there is now less code to maintain. Futhermore, I find that the code for new field types is easier to write. I add to the ROLLED OAT repository, and there is a field available to add into any point of a taxonomy. And, if I conform to a few simple guidlines, the fields add their validation checks, data formatting, and visual presense in a way that seems as if they almost as if they did it themselves.

How does the ROLLED OAT package yield up the form interface? Well, every rendered part of a page from drupal, via drupal_render, requires that the module presenting a form or even other objects be checked for a subroutine, theme_, with the form elements as a parameter. So, I have made at least one routine theme_rolled_oats_, e.g. rolled_oats_tab_set, and theme_rolled_oats, for general purpose ones. The rolled oats theme type has it's own types, which are names of elements in a repository. So, you can put these into a PHP routine for making a form, or you can let the module rolled_oats_content execute a generalized version of operations determined by editing the content type with the content definition form.

So, should you write your own module? Help me get this one working. Otherwise, it was a few intense weeks of staring at it all for a while, giving each line a few long lapses of time. You might want to do that yourself. But, I could use some help.

I think what is at issue here is the dependency on a server and DB to do a certain amount of work, while javascript toolkits are evolving rapidly. Perhaps small devices will require that not too much javascript will be used. But, I really think that they are just getting more powerful with more memory, color screens, etc. Soon cell phones will be like CRAY's and we'll all run Manhatten when we message our friends. So, I don't think CCK would want to remain to intimintly tied to the server as time progresses. As such, it will have to change at some point. But, you can have ROLLED OATS today , or in a few.

Must run to a movie... Need some debugging. Need to get back to this. And, I want to emphasize coexistence. So, later. Please comment this or put a comment on www.classydex.com

Thanks....

det-1’s picture

what if you need a multipage form and need to save the result on every step/page and not just after all the pages has been completed. I also need to use the availability module on my form. availability module becomes a collapsible block when you add it to a content type. what I need is to make the availability block appear only in one step/page. I have tried cck witch which allows multipage cck but add on modules like availability appears on all the steps/pages. Moreover the cck witch currently cannot save info by step/page. You have to go through all the steps/pages to save the info.

I also have other fields like google maps which is also needed in the new node type.

So, which do you think is better tweak cck/cck witch? or create a custom node type via a module?

If I create a custom node type, can I possibly reuse/invoke cck fields? which means can i use the imagefield module for instance so i don't have to code the image file uploads anymore? is there a way to hook to the cck fields from a custom content type module?

thanks very much in advance.

juicytoo’s picture

Hi,

Hope someone can direct me to some examples so I can cut and paste.

I have a custom module I copied.

I would like to create this using cck programmatically so I can get the freebies that cck throws in, like node_import and others, instead of recreating all the methods that work for cck.

Could someone please point me in the right direction as to how to program a cck module.

I'm not sure if its in the *.install file. An example would be great to cut and paste from.

Is it possible to make a cck programmatically in during a module install. ie. not a install profile but during a module creation process but calling the cck create functions?

cheers

yasheshb’s picture

http://drupal.org/node/101742 is a good point to start.

yashesh bhatia

Yashesh Bhatia