0

I'm fairly new to Drupal. But I'm trying to learn.

What I'm try to accomplish is have a variable in a certain node type (artist) and I want to access this variable in another node type (news). Is this possible?

Let's say I have two content types, Artists and News. The artist node will have (at some point) related pictures, songs, and news. But at default it does not have any. So I wanted a variable that acts like a flag that if there are any related pictures the flag is changed. In the news node, I have tags that point to an artist if the news is related to him/her, then I'll show the same related songs, pictures of the same tagged artist. I want the flag variable as a checker if there are truly related songs/pictures. In that way I'll just use the flag and before I query the related pictures/songs

  • 1
    What do you mean by variable? Is it supposed to be something different than a field? And what exactly do you mean by accessing it from another type? Please provide simplified use case :) – Mołot Oct 9 '13 at 12:33
  • 1
    Sounds like you are wanting some sort of node or entity reference field, but without further information, that's only a guess... – Jimajamma Oct 9 '13 at 12:49
  • check this module drupal.org/project/entityreference as mentioned by @Jimajamma – Bala Oct 9 '13 at 12:52
  • Let's say I have two nodes. Artists and News. The artist node will have (at some point) related pictures, songs, and news. But at default it does not have any. So I wanted a variable that acts like a flag that if there are any related pictures the flag is changed. In the news node, I have tags that point to an artist if the news is related to him/her, then I'll show the same related songs, pictures of the same tagged artist. I want the flag variable as a checker if there are truly related songs/pictures. In that way I'll just use the flag and before I query the related pictures/songs – user21688 Oct 9 '13 at 12:55
  • 1
    @user21688 you are supposed to edit your question. Comments are ephemeral in nature, and here you can't expect them to be read by anyone but the person who asked. As the text says, they are here to ask for clarification, not to provide it. They can be deleted without notice and no one will bother. I'll edit your last comment into your question for you now, but next time please do it on your own :) – Mołot Oct 9 '13 at 13:02
1

What you are looking for is, basically, Entity Reference, as mentioned by Jimajamma and Bala:

Provides a field type that can reference arbitrary entities

Just add entity reference field to news and allow artists to be selected. For pictures and songs, use either simply fields in Artist content type, or repeat the process - create content types for them, and add entity reference fields to artist content type.

Now, for display consider Views - it can use entity reference field to show all songs by artist in setup like that. I believe that's the easiest way.

  • I'll look into this. I'm not very familiar with drupal yet. I'll read in to this. – user21688 Oct 9 '13 at 13:26
0

If you are using terms to relate the nodes, you can create a view that shows the related content by using relationships via the taxonomy term.

Then show the view on your node page and if there are no related content then the view will just not display.

You will still be running the query even if there are no results, but that shouldn't really be an issue unless you have a very complex view and very large amounts of content and no caching.

Another way you could do it if you prefer is to create a checkbox field on your node as the flag you refer to, then using the rules module you could set that flag on node save, based on other field data.

Then you could use that flag to do whatever you are planning.

I would recommend the first option though.

  • This is what I have done. and I use the views_get_view_results(). But Unfortunately, I'm going to query a very huge amount of data. Like in millions. Just imagine almost all artists with along with their songs along. – user21688 Oct 9 '13 at 13:25

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.