开发者

drupal multiple content type reference

Drupal has content types set as:

- Book
- Contributor

Custom CCK fields are added to above content types.

Contributor has type id set as:

- Author
- Seller
- Reader

The above contributor type id is to be added (currently with node reference) to "Book" with Author and contrition typpe "Seller".

example:

Book                    Contributor     Contributor Type
--------------------------------    --------------  ---------------
Act Like a Lady, Think Like a Man   Steve Harvey    Atuhor
Act Like a Lady, Think Like a Man   Steve Harvey    Seller
The Alchemist               Paulo Coelho    Reader
The Happiness Project           Gretchen Rubin  Atuhor
The Happiness Project           Gretchen Rubin  Seller

What would the best approach to achieve this. With current setup we are able to add contributor id, how to ad开发者_如何学编程d "contributor type" with it as well.


If I understand you correctly

  1. You have 2 content types. Book and Contributor
  2. The Book content type has a node reference field which points to nodes of type Contributor
  3. There can be three kinds of contributors: Author, Seller and Reader
  4. From the Book content type you want to be able to select the contributor (via Node Reference) and mark the the contributor type as reader, seller, author etc. (In some ways you want to add an "attribute" to the Node Reference or "describe" the Node Reference)
  5. Also this way its possible for a contributor to be in more than 1 category. e.g. A contributor can be an author and seller also.

Actually your question, if I have understood correctly is a good one. The answer is not trivial.You need to somehow "group" the node reference field with a select list. This way every time you make a node reference, you also select the contributor type. What you're asking for essentially is "Multigroup" feature. Its available only in CCK version 3.You cannot do this with CCK Version 2 series which is what you're probably using. Unfortunately a stable version 3 of CCK is still not available. However a development is available at http://drupal.org/node/484068 . As of today, a lot people are using this version already (see http://drupal.org/project/usage/484068 ) and from what I've read, its quite stable already.

So in summary:

  1. Install CCK 3.x-dev from http://drupal.org/node/484068 in your sites/all/modules folder. Remove the CCK 2.x folder if it exists there. Please take backups etc. of your site -- just in case something breaks.
  2. Enable the Multigroup module (under the CCK module listing)
  3. Create a Multigroup lets call it MG. You can do this under Manage fields -> Add a New group (Select Multigroup from the dropdown)
  4. Create a Node Reference field to Contributor Nodes, lets call it Link to Contributor. Make sure the parent of Link to Contributor is MG (you can achieve this by grabbing the anchor and moving the field to the right, just like you do for a hierarchical taxonomy tree.
  5. Create a contributor type select list field with three options (Seller, Reader, Author). Lets call the field Contributor Type. Again, make sure the parent is MG.
  6. Now test this by trying to create nodes of type Book. You will be able to select the Contributor and the Contributor Type. To add more Contributors to a book, simply press the Add More Values in the Node Edit Form.
  7. For Views integration you need to install Views version 3.0-alpha3 or higher. You will need to add a filter under under the Content Multigroup group.

And BTW since I found your question interesting, I've tried it out and it seems to work correctly for me!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜