3

I want to create in Drupal 8 a content type called Book with some fields you'd expect to be associated with it. Title, Author, Date, ISBN, URL

(I want two other content types: "Book Review" and "Book Author.").

I expect to do a lot of different things with books; it's much easier to have a separate content type for it which I can reuse.

The user (or the admin) would initially use the input form to publish the "Book" (i.e., To Kill a Mockingbird, Great Gatsby, etc)

Next a user having the "Book Reviewer" role would have an input form to publish his review (Title, a text field containing the review, a summary, rating) and publication date.

Here's the thing I don't understand.

Tom (who has the Book Reviewer role) would log on, select "Add Book Review". For this to work, Tom would need some way in the input form to look up the available book titles already inputted by users in order to choose the specific book he wants to review.

Can you accomplish this in Drupal 8? What is this functionality called? Could this reverse lookup be easily done from the Book Review input form? I'm unsure exactly how to implement this. I've seen explanations about how you can look up a specific user in the input form, and maybe from the DB point of view, all nodes are the same. But I'm not sure if looking up users is a special case.

Some more details:

  1. I have seen that relationships are a way to connect fields from two different content types. But I'm unsure if you could display this kind of lookup function in the input form!

  2. I can' predict how many books will be added or need to be looked up (maybe 50-1000?). But is there any hard limitation on book nodes you could search through?

  3. Is this something you could do through Drupal core without needing to make a module?

3

R3: You don't need to write any code :-)

R1: The relations are managed with the field Reference by content (provided by core) take a look inside the Add a reference field to content type section in How To Reference Nodes in Drupal 8 + Views Relationships Display

Then you can go to configure your content type display mode and form display mode to change the widget if you want another different from the default widget. See Exploring the New Drupal 8 Display Modes and How "form modes" work in Drupal 8 and how to add and edit them

R2: You can have 1000 books without problem, in this case I recomend to use the autocomplete widget.

If you want to add more functionalities to your relation you can use the following modules:

Entity Reference Views Select

A module for those who need their Entity Reference Views fields to be displayed as a select list, checkboxes or radio buttons in forms.

Inline Entity Form

Provides a widget for inline management (creation, modification, removal) of referenced entities. The primary use case is the parent -> children one (product display -> products, order -> line items, etc.), where the child entities are never managed outside the parent form. Existing entities can also be referenced.

  • 1
    Aha, BOOK REVIEW --> MANAGE FORM DISPLAY --> (Change the WIDGET default for BOOKTITLE to AUTOCOMPLETE). Now I understand! Thanks! – idiotprogrammer Aug 19 '17 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.