0

I have the following problem I can't figure out how to solve - note I am a Drupal newbie...

I have two content types; TypeA and TypeB. TypeA includes an entity reference field of TypeB to create a static relationship, similar to a "related work" or "is part of" use case.

This relationship displays fine in the full display mode for TypeA and all is well on that front.

I fail, however, to display this relationship as a mapping table in a third content type, where all TypeB nodes represents columns, and all TypeA nodes are displayed in individual rows like the following example:

Example:

Consider we have the following three nodes of TypeB: NodeA, NodeB, and NodeC.

We also have 5 nodes of TypeA, all along with the following relationships to TypeB nodes as follows:

  • Node1 (NodeA, NodeC)
  • Node2 (NodeA)
  • Node3 (NodeB, NodeC)
  • Node4 ()
  • Node5 (NodeA, NodeB, NodeC)

The mapping table then would look like this:

      | NodeA | NodeB | NodeC
------|-------|-------|------
Node1 |   X   |       |   X
------|-------|-------|------
Node2 |   X   |       |
------|-------|-------|------
Node3 |       |   X   |   X
------|-------|-------|------
Node4 |       |       | 
------|-------|-------|------
Node5 |   X   |   X   |   X

Obviously, I do not want to maintain this table manually, but be built depending on the actual dynamic content of the site.

EDIT

The following constraints also apply (forgot to mention them in the first place):

  • When I unpublish or delete a node of content type TypeB, the entire column of this mapping table needs to disappear
  • The view (anticipating that I can implement this through crafty Views configuration) should not be cached, or cache-cleared upon change (is that even possible?)
  • The "X" in the example table would ideally be replaceable with other code or content I control (e.g. a little image, or glyph or so)

Thanks a lot,

Michel

1 Answer 1

0

I don't think you can build that with views or another UI tool just by clicking it together.

It should however not be too complicated to build with a but of custom code.

You need to build an entity query that gets all TypeA nodes, another one that gets all TypeB nodes, loop over Type, and for the columns, loop over the Type B and check if you have a reference for them in your field.

IMHO writing out the full code is too much for a single question, I suggest you get started and if you have problems, ask specific questions.

Obviously that table will get huge if you have a lot of nodes of either type or even both.

1
  • Thanks. I had hoped that there is a solution for that as I (perhaps wrongly) thought this to be a common problem. I do understand and can read PHP, but I have no idea about coding against the Drupal inner guts, so that would be very daunting and long-winded... The size of the table is not a matter as it will have only about 5 TypeB columns, and around 10 TypeA columns - but they will change over time without changing much of the overall amount (i.e. adding and removing).
    – MDr
    Commented Mar 18, 2018 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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