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
- You have 2 content types.
Book
andContributor
- The
Book
content type has a node reference field which points to nodes of typeContributor
- There can be three kinds of contributors: Author, Seller and Reader
- 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)
- 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:
- 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. - Enable the Multigroup module (under the CCK module listing)
- Create a Multigroup lets call it
MG
. You can do this under Manage fields -> Add a New group (SelectMultigroup
from the dropdown) - Create a Node Reference field to Contributor Nodes, lets call it
Link to Contributor
. Make sure the parent ofLink to Contributor
isMG
(you can achieve this by grabbing the anchor and moving the field to the right, just like you do for a hierarchical taxonomy tree. - Create a contributor type select list field with three options
(Seller, Reader, Author). Lets call the field
Contributor Type
. Again, make sure the parent isMG
. - 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 abook
, simply press theAdd More Values
in the Node Edit Form. - 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!
精彩评论