I’m working on a project that partially involves the development of a website in Drupal to act as a directory of people who have graduated from a given University. Seems easy. I went into the project thinking it would be a trivial application of Taxonomies, or maybe some generic CCK fields.
Nope. Turns out the problem is much more difficult and complex than I initially thought.
Taxonomies won’t work, because of the need to tie a number of values together, namely the year the degree was awarded (say, “1992”), the type of degree (say, “BSc”), the specialization of the degree (say, “Zoology”), and the granting institution (say, “University of Calgary”).
That could be an easy thing to solve with CCK – just add four text fields. Done.
BUT – people can earn more than one degree. Of different types, in different years, from different institutions.
Taxonomies fail. Generic CCK fields fail.
What I came up with is a new CCK field type, cryptically named “University Degrees”, that defines the four values that describe a degree. This solves the problem quite tidily, and supports multiple values, predefined valid sets of values, and can integrate with Views to be used as filters and sorting fields.
In building this module, I leaned heavily on a couple of web pages (CCK Sample and What is the Content Construction Kit?) that describe how parts of the module should work, and provided some sample code. In the spirit of contributing back what I learned, I’m going to document the module to help others needing to do similar things.
Continue reading “Creating a custom compound field for CCK”