1

I have a content type "songs", lets say a node has a reference to 4 or 5 other nodes. What I want is when I create a new node, I just need to make a reference to one node and the other 4 nodes will be loaded automatically.

Is that possible?

  • Is this drupal 8 or 7? Also are you creating new 'song' nodes in code? Or are you making them in the drupal menus? – Matt Dec 5 '16 at 16:30
  • I'm using drupal 7 ! i making them in the drupal menus (the simple way !! ) thank you – MohK Dec 6 '16 at 14:16
  • How are you referencing them, and what are you using them for? Do you have a section displaying 'related songs'? – Matt Dec 6 '16 at 21:20
  • Ok ! I have a content type "songs" , i have two type of songs "original" and "remix" , and when i create new remix i make reference to the original song , and every song have multiple remixes ! so what I want exactly is ..when I make remix 1 to original A , and make remix 2 to original A also ! the remix1 & remix 2 make reference automaticly ! without need to make reference one by one ! hope you understand me thank you – MohK Dec 6 '16 at 21:50
  • Do you just want every remix referring to a specific song to show up on a song's page? – Matt Dec 7 '16 at 20:04
0

Broadly if your node reference is required your user must to fill it on node creation. So you could try to use hook_node_presave or in the form layer you could have your submit handler to deal with that. Once you get the reference chosen by the user you would need to retrieve the other 4 related references that will be also added as siblings in the multi valued node reference field. By another hand if you want to make all of this visible in the form before it gets submitted you could use hook_form_alter (in case you don't have your own hook_form) to add a behavior to the node reference field form element and if it has just a checkbox widget you could simply automatically check the other nodes to be referenced using the behavior to react the check box that has been checked.

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.