Creating CCK Multipoles

    This topic is a kind of response to the non-trivial task for the Node Reference Drupal field and the Module for the culinary site . But, unlike the authors of those two topics, I’m not going to reinvent the wheel and write my own decision, but simply show how this problem will be solved in the near future (and now, in general, it’s already possible), and what will become the de facto standard in Drupal. Why am I so confident about the standard? Everything is very simple - we will talk about the CCK (Content Construction Kit) 3 .

    Generally speaking, as far as I know, grouping several CCK fields into one multipole is the main reason for the appearance of CCK 3. This function is popular (I have to deal with it in almost every Drupal project) and every time I have to write a new CCK field (or reuse operating time) to get a new field consisting of simpler ones. And writing a CCK field is a rather routine task, which takes not so little time (depending on the complexity of the final field). After this task appeared on my horizon once again, I decided to conduct a little research on this topic on the Internet - for the task is far from unique, and many should have faced it (one of the proofs of this is 2 topics on this topic for the last week on a habr).Development releases on the project page . There are two ways to get to the download: either look at the entire history of releases in the corresponding section , or from the Reports -> Available updates page of any Drupal project where Update status and Content modules are installed (basic CCK module).

    But enough lyrics. Let's already make our culinary site with preference and courtesans using CCK3, or to be more precise - Content Construction Kit (CCK) 6.x-3.x-dev (2010-Jan-26).

    As a preparation, we will have 2 content-types - Ingredient and Recipe - Ingredient and Recipe, respectively. So far, these are 2 content-types with absolutely standard settings.

    Let's create some ingredients - they will come in handy for further testing (I just set the headers for the nodes). Next, we go into the installation of the modules, and include what is useful to us - and these are Content Multigroup , Node Reference, and Text . The installer of the modules itself will deliver everything that it lacks. Now we go to the Recipe content-type field management and add 2 fields that will be responsible for 1 ingredient - the ingredient itself (Node reference to the Ingredient content-type) and quantity (here I just used the Text field). And from this moment, the special Multigroup magic begins. Add the Ingredients group to the recipe fields, add the Ingredient and Quantity fields to this group, and set the group type to Multigroup.

    Still, for a more convenient display of this particular example, I set the Multiple columns checkbox in the field settings - the fields within one multipole will not go one below the other, as it usually happens, but in 1 line, which for a small number of simple fields (as in our case) conveniently.

    Finally it's time to create our first recipe. Describe what and how I think it’s not worth it - everything should be clear in the screenshot: After saving the node, we will see something like the following: So far it’s not very beautiful, but it already works =) We will have a little chat with the display of the fields: And we will get a pretty nice recipe:

    Here, in general, and all that I was going to tell about the new CCK3 feature. It remains to add only one thing - the module is in the dev state, and its use in production is not recommended by the authors of the module. Although, according to statistics , the module is already used on 6.5k + sites that have the function of automatically checking the status of the modules, and not the fact that they all live solely for review =)

    Also popular now: