📜 ⬆️ ⬇️

Creating CCK Multipoles

This topic is a kind of answer to the Nontrivial task for the Node Reference Drupal fields and the Module for the culinary site . But, unlike the authors of those two topics, I don’t intend to reinvent the wheel and write my solution, but I’ll just show how this task will be solved in the near future (and even now it’s already possible), and what will become the de facto standard in Drupal. Why am I so confident about the standard? It's very simple - we will talk about 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 in demand (I have to deal with it in almost every Drupal project) and each time I have to write a new CCK field (or reuse practices) to get a new field consisting of more simple ones. And writing CCK-fields 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 do a little research on this topic on the Internet - because the task is far from unique, and many had to face it (one of the proofs of this is 2 topics on this topic last week on Habré). After a short googling, I came across CCK 3, which is now in the dev state, and the download link is not even listed in the Development releases on the project page . You can exit the download in two ways - either look at the entire release history in the appropriate section , or from the Reports -> Available updates page of any drupal project where the Update status and Content modules are installed (the basic CCK module).
')
But enough of the lyrics. Let's 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 blank, we will have 2 content types - Ingredient and Recipe - Ingredient and Recipe, respectively. So far, these are 2 content-types with absolutely standard settings.



Create several ingredients - useful for further testing (I just set the headers for the nodes).



Next we go to the installation of modules, and include what is useful to us - and this is Content Multigroup , Node Reference and Text . The module installer will deliver everything that it lacks.



Now we go to the management of the content-type Recipe fields and add 2 fields that will be responsible for 1 ingredinet - the actual ingredient itself (Node reference to the Ingredient content-type) and the quantity (here I just used the Text field).



But 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 type for the group to Multigroup.



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

Finally it's time to create our first recipe. Describe what and how I think is not worth it - everything and so should be clear in the screenshot:



After saving the node, we will see the following:



So far, it is not very beautiful, but it is already working =) Let's do a little with the display of the fields:



And we get a pretty beautiful recipe:



Here, in general, and everything that I was going to tell about a new feature of CCK3. It remains to add only one thing - the module is in the dev state, and its use for 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 modules, and it’s not a fact that they all live only for familiarization =)

Source: https://habr.com/ru/post/83319/


All Articles