CCK - CoCKTaiL Part 3

· 2 min read

Original publication

This post was originally published on February 11, 2008 on The Standard, the Raincity Studios blog, credited to “Djun Kim”. This post reflects the context and tools of its time; some links and services mentioned no longer exist.

View the original on the Internet Archive

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:

  1. map supplied attributes to attributes in the given type (these include type attributes, group attributes and field attributes)
  2. 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

There appear to be lots of interesting challenges to be worked out. Stay tuned, or better yet, pitch in and help - and in the meantime, don't forget to vote for my session.

Your business deserves to be found.

Tell us about your project. We answer in English or French, and we travel anywhere in the MRC de Papineau.

Display

Your choices stay in this browser. Nothing is sent.

Text size
100%
Colours
Reading
More help
Site accessibility