CCK - CoCKTaiL Part 3
Update
As promised in my last post, I will present a CoCKTaiL-based code-generator, which accepts CoCKTaiL input and generates php suitable for importing into Drupal via the CCK Content-copy module.
DrupalCon Session
I have submitted a session proposal on Taming CCK configurations with CoCKTail for DrupalCon Boston. Please consider reviewing this and voting for it if you would be interested in seeing CoCKTaiL gain a wider following.
Code available via anonymous SVN
I have made code available via anonymous svn at Raincity's public SVN repository. I encourage anyone interested to have a look at this, take it for a spin, and contribute! But, be warned that this is still very experimental code.
Status
The current version of the code supplies a command-line validator, which checks CoCKTaiL code. The error reporting is extremely naive, still. Also, there is a template-based code generator, which will take CoCKTaiL as input, and generate php code suitable for import into a Drupal application. Both of these are specified as PHP Lemon input files, sharing a common grammar (and Lexer), of course.
The CoCKTaiLcode generator can now generate text fields; support for remaining 'core' fields will be implemented in the next few days. . There is some support for links and noderefs.
Template based code generation
In order to write a code generator that generates CCK-import specifications (PHP) from CoCKTaiL input, we will need to:
- map supplied attributes to attributes in the given type (these include type attributes, group attributes and field attributes)
- provide default values for each required attribute that is not explicitly named
To do so will require having knowledge of CCK types and fields and their allowed and required attributes.
The output will be a PHP array containing a type specification.
The strategy: templates
We will supply a template for all default attributes. The values provided by parsing the CoCKTaiL description will be written over the template values, if they have an appropriate value.
There will be a template for each of the following:
- type attributes
- group attributes
- field attributes
Field attributes will have to added for each new field, since CCK is of course extensible.
A few details
Because one of the goals of CoCKTaiL is to make life easier for developers, we go a little beyond merely copying in supplied attributes into a template. In particular, the published status, comments, and a few other commonly used attributes for nodes can be supplied as scalar attributes, rather than as array values.
That is, we can write
...
status true;
comment 2;
...
rather than
...
node-options array(
status true;
comment 2;
...
);
...
In addition, templates can contain stubs which are substituted for at code-generation time.
Next steps
As mentioned, I still need to create the templates for the remaining core CCK fields. I hope that in doing so, I will be able to validate the usefulness of the templating approach to code generation.
Some of the major issues which still need to be addressed are:
- how to deal with shared fields
- how to automatically generate relations
- how to deal with versioning












Cocktail Status?
I've been watching this blog for a while, hoping that you'd move forward enough on Cocktail for a relative non-programmer (such as me) to try using it to build a CCK-based module. I downloaded the code from your SVN link, but honestly don't know how I'd use it to make an abstracted description of what I want, and then actually get it implemented on a Drupal website.
Given the whisperings on the wind (that CCK is going to be put in Core, CCK will soon change everything, etc.), having a method for managing CCK-built functionalities would seem to me to be of utmost importance.