This is my project proposal for the Summer of Code 2007. Better multiple value handling in CCK is needed and could be useful to a lot of people, so I am interested in having your opinion before I officially submit this project proposal to Google.
Motivation
The current implementation lets individual CCK field modules handle multiple values themselves. This approach is simple but it limits the flexibility of CCK content types in various ways. Issues with multiple values are very common in the forums and on the CCK issues list, but the answers received are never straightforward and clean.
The proposed project is a module that would set the bases for a new method for handling multiple values of CCK fields that would be more unified and flexible than the current implementation. The main goal is to be able to group multiple values together so that the database schema reflects the logical organization of the data.
A practical example is easier to understand than an abstract description, so suppose I want to create a recipe content type using CCK. For the ingredients, I need a list of items containing: the description of the ingredient (text), the quantity (number) and the unit (select: grams, liters, etc). Logically, the database structure should be something like:
| delta | ingredient_name | quantity | unit |
|---|---|---|---|
| 0 | Whole wheat flour | 500 | gr |
| 1 | Lemon Juice | 10 | ml |
but currently, if I create fields for ingredient names, quantities and units, all of them having multiple values, I get three tables of the form:
| delta | ingredient_name |
|---|---|
| 0 | Whole wheat flour |
| 1 | Lemon juice |
| delta | quantity |
|---|---|
| 0 | 500 |
| 1 | 10 |
| delta | unit |
|---|---|
| 0 | gr |
| 0 | ml |
Having the data stored this way in the database makes it difficult to update, sort or view it in an efficient way while keeping relationships between row elements consistent.
Several workarounds currently exists, fieldgroup_table, subform or editview just to mention a few. I recognize the effort put in these modules, but fieldgroup_table has unsolvable input validation issues, and editview and subform require to create nodes for sub-elements, which is not always appropriate (for example in the case mentioned above, 10ml of lemon juice does not mean anything by itself). What we need is a solid module that reflects the logical structure of the data from the user interface to the database.
General Idea of the Implementation
The "multiple values" attribute of individual fields is replaced by a new field type that acts as a container. Let's refer to this new field type as a "multiset" field. Any field type could be created inside a multiset.
In addition to the fields it contains, a multiset field would also have settings for the input method. Possible widgets include:
- a list of fields similar to the current input widget for multiple values. The number of empty fields presented to the user on node creation and modification is customizable.
- a list of fields with a link or button to add a row using JavaScript (AJAX is not required since all elements added follow the same template). A link or button to delete a row should also be available on the side, since setting many fields to their empty value can be cumbersome, especially when using multiple select widgets (like the date module).
- a predefined set of fields, each of which is associated with a key value in a similar manner as the inventory module (link). Depending on the implementation details, this kind of multiple values might need to be handled in a separate module using the same common functions with only some slight differences.
Setting the 'required' attribute of a contained field would then indicate that any non-empty row needs to have a value for that field.
If the data is organized logically at the database level, it will then be easier to implement different formatters for multiple-valued fields.
Planned Issues
Since CCK has rapidly become an essential contributed module for many drupal-based websites, compatibility of the new module with current modules is crucial. By ignoring the 'multiple' attribute of the fields inside a multiset field, the new module can use any CCK field without needing to make changes to existing modules.
There also needs to be a script or a separate module that make it possible to update current data to the new structure by converting fields with multiple values into multisets containing the original fields.
This multiset module provides powerful but abstract functionalities, so having a clear and meaningful user interface is important in order not to confuse inexperienced users.
Long term
When this module becomes part of the core CCK modules, the creation of new CCK field types will be made easier because field module developers will not need to write (redundant) code to handle multiple values.
Credit
The motivation came from working on a few Drupal-based websites that gave me trouble with multiple values handling in CCK. However, the idea to step apart from CCK's current multiple value handling at the database level was inspired by the Inventory module.
I'd like to thank Robert Douglass for his useful suggestions to clarify the goals and purpose of this project, as well as the many Drupal developers without whom this project wouldn't be possible.
About Me
I'm a student in mathematics and computer science, and I do web development as a part-time student job.
After having worked as an intern or a part-time employee in different software companies, I have realized that open-source does make a difference. I believe in the values it represents and I hope that the Summer of Code experience can be a first step for me towards a professional career in the open source world.
99% of the software I use is open-sourced, whether I'm writing a paper, doing development work, recording music with my band or simply reading my e-mail, and I have convinced people around me to do the switch too (my girlfriend now runs kubuntu on her laptop and my college's website will be drupal-based as of next fall!).
Considering how much I have gained from Drupal and open-source software in general, I'm extremely excited at the thought of spending the summer making a contribution to this wonderful project.
Comments
That sounds like an amazing
That sounds like an amazing idea!
Multiple value fields in cck could definitly need some love, and your concept sounds pretty well-thought!
cck needs you!
This sounds like an awesome idea... Don't forget we still need to have non-multiset groups... I don't think it will be a problem though. I really like this idea. If you need help or feedback, please contact me directly via irc, dopry or my contact form on drupal.org.
Go man, go!
Exactly what I've needed.
~ ben melançon
member, Agaric Design Collective
http://AgaricDesign.com - "Open Source Web Development"
benjamin, agaric
What's a girlfriend?
What's a girlfriend?
Can't wait !
Hey,
You got a bright ideas. I wonder why it's been done before ! I wonder how the Recipes website are doing today without it. I hope you could do it (I need it also for a website, and don't know exactly how to get around in between :/
So go go !
Is this project still in progress ?
Hi,
This project would be very useful.
I have not seen this project in the google summer code list.
Are you still working on this ?
Yes please: the multiple value handling needs to be improved
One thing that you mentioned and that is even more important to me than the database schema used is the fact that from a user interface point of view, multiple value fields are currently absolutely unusable
(for most field types at least)
What we definitely need is something with an 'add' button to add another row. that row must have a definable name, i.e. in your example it would be "Ingredient" but in a list of music tracks on a CD it would be "Track" (and hence the Button should there say "Add Track")
the fact that for most types the user doesn't currently have such a button but has to submit the first three rows in order to be able to add 2 more etc. makes the current way unusable and the need for that Add Row Button is really urgent.
so how are things going on?
would be ideal for questionnaires
I can only add my voice to these here! Without this kind of fieldtype it won't be possible to use Drupal for serious questionnaire creation. How does this proposal relate to the issue for webforms: http://drupal.org/project/issues/7404? I guess that would be basically the same thing but much less generic, i.e. just for forms.
For D6 ?
This should be much easier to do with the currently-in-progress CCK for Drupal 6.
In short, multiple values handling gets out of individual field modules, and is handled by core CCK (content.module).
This ensures consistency of 'multiple values' feature across all field types, removes a good deal of code duplication across field modules, plus opens the door to quite a bunch of often requested features, including this one, which could probably come as a flavour of fieldgroups.
See http://drupal.org/node/157176#comment-295409 for more technical details about CCK changes in D6
Pretty Please
I'm scratching my head trying to figure out how to achieve scalable "groupings" and I found your post through Google doing research. Good job describing the problem. Thank you to you and the other geniuses who make things like this work.
In the mean time however, what is the best work-around? I'm a Drupal newbie... but the best thing I could think of (to stay with your example) was to create a Content Type for each ingredient. Then assemble them in views or something?
This actually makes no sense for your example, but for me (I just want to upload an array logos and provide URL for each logo).
and other abilities
And if the sample problem of the recipe/ingredients was done as suggested above by ecksley, you can then create a library of ingredients and add them to your recipe. e.g. a single ingredient node could be "salt 5 mg" which you might want to add to numerous recipes.
I do, however, see the value in a solution like this. I did one project where the client needed a form where they could add numerous (but undefined number of) contact links (name, email, city) to their node. I tried doing this with the subform module but the UI for it was very messy. In the end i used the relativity module with a link to "add new sub-item". This worked ok, but this idea would have been cleaner.
From the lokos of things however it does seem as though this project has died - too bad.
Peter Lindstrom
LiquidCMS
Peter Lindstrom
LiquidCMS - Content Solution Experts
An approach
I would suggest that the best way to approach this would be to allow Content Types to be associated. We could create a content type for ingredient and then a content type for recipe.
Refer to http://groups.drupal.org/node/7645
Nathan
Taxonomy?
Maybe this can be done through writing a small module using taxonomy? I have not tried it yet tho.
Another way is allow creating content along with its related content (with different content type), just like Views. For example when creating a content 'Recipe' you get a add/edit 'View' form which combines 'Recipe' and 'Ingredients' on the same page.
Any updates on this ?
Is there any progress regarding this proposal ?
ditto
I was wondering if you got any traction for this idea? We keep coming across uses for such a thing and yet cannot find development in progress on such a widget. I know this is supposedly going to be easier for D6, but we are brainstorming modules we might contribute, and there might be quite a bit of use for a D5 module that does this, that could serve at least as the functional basis of the D6 version?
It's very unlikely that
It's very unlikely that anything created for D5 would work in D6 because they are completely different. The maintainers of CCK have had numerous discussions about whether there was any way to get this working in D5 and couldn't come up with a way to do it, so don't underestimate how difficult a project this is. And it won't migrate, so it would work for only one version.
If you want to try it, go ahead, there are lots of people who'd like to see it, just don't be surprised if you find out the only way you can get it to work in D5 is to replicate lots CCK code in your custom module so you can tweak to work differently than it does now, and that it will only work for a small subset of CCK field types no matter what you do.
The reason we keep talking about the D6 version is that it has been designed completely differently with an API and self-validating FAPI elements. More importantly, in the D6 version the content module handles multiple values, not the fields, so you don't have to find custom work-arounds for each field to get them to treat multiple values differently. The reason no one has done anything with the D6 version is that all of us that know enough about the code to do it are too busy working on the code to try it.
Update?
Has there been any development on this? This would be a huge improvement to the CCK and I have several items that could benefit from it. Let me know if I can help and what the status currently is.
Duck!
Work for a 'combo field'
Work on a 'combo field' ('combo group' actually) has started on http://drupal.org/node/119102
And this is now available in CCK3
Please, see State of the multigroup module. Comments #1 and #3 can give everyone an idea on what it is and what's left to do.
This is exactly what I am looking for!
A multi-value text and number combo filed sample...
So far,
How about?
A simple multiple value example as suggested by flobruit which teaches cck newbies how to create a compound cck field:
Any one?
Generics can reduce code redundancy and most good idea.
In my college education time I have some challenges with generics in CPP programming language.
Generics is exactly what I am looking for.
Generics can reduce code redundancy and most good idea.
Please see this form widget and attend to ahah/ajax capabilities used on that before you do any thing:
http://www.starbowconsulting.com/blog/tao/dynamically-expanding-ajax-aha...
also i am ready to help to develop this concept in drupal 6
i'm dealing with this case,
i'm dealing with this case, i'll check every link :)
azul
myBlog