Posted by bstoppel on January 26, 2009 at 5:23pm
I am working on porting a minimal version of the Bibliography module to CCK. I am doing this as the Biblio module doesn't serve my exact needs. On of the UI elements that the Biblio module does that I would like to mimic is a context specific fields for data entry depending on the selected publication type.
For instance if a "journal article" is selected as the publication type, a field for the "start page" is shown. If the publication type is a "book," the "
"start page" is not relevant and is not displayed, but other fields such as "number of pages," "volume," "edition" are made visible.
Is such a thing possible with CCK?
Comments
First of all, why wouldn't
First of all, why wouldn't you just create different content types for each of these? Then you could put the right fields on each one and would need no customization at all?
If you're going to do it anyway, you will have to use hook_form_alter() and nodeapi() because you want to alter other fields than the field you're creating, probably setting #access=FALSE on the fields you want to hide. The whole basis of CCK is that each field is an autonomous entity that only cares about itself, so there are no built-in ways you can use one CCK field to alter others. And it's tricky to figure out where to do things like set #access in CCK because the view is cached and the form is built out in #process (which happens after form_alter()). So, again, it would be much easier to just do this with different content types that have the right fields on them.
Taking up Karen's first point
Taking up Karen's first point, I began working on an aspect of this in conjunction with the Book Review module (http://drupal.org/project/bookreview/).
My idea there was to create several CCK field modules that one would link together to create a Book Review node type. As I mentioned in http://drupal.org/node/283617, I am not much of a Drupal developer, so take EVERYTHING I say here with that in mind.
I took the Address field type and hacked it heinously to shoehorn very basic bibliographic information into it. The version I uploaded there includes a setstruct function that holds information about the fields included in the module.
I think that it should be possible to derive further entity types (journal articles, etc.) from the approach I took there, adding different elements as needed. Changing the array and the function/file/folder names in theory should create a new entity.
Of course, I may just be an idiot here, but that's rarely stopped me from sticking my foot into it before.
David