0

Scenario

A Content Node's URL needs to be incorporated into an Application (Node Add) for a future reference so the users can view their Applications made. The user clicks on a Rules Link (i.e.'Contact User') button and the user is taken to a Form (which for my purposes creates a new content Node 'Application',so the entity is Prepopulated with the referring Node URL (or a linked Title) so the user can later view it in a list and for backend managment purposes, the Application Nodes will be CRON purged once in a while as required.

I have installed https://www.drupal.org/project/entityreference_prepopulate module along with Tokens but it doesn't included the previous Node URL as expected although it does add the 'current' mydomain.com URL, so it's working to some degree. And yes, I have looked at online Youtube etc videos, but they don't seem to cover my requirements.

I'm at a loss understanding how the process is working backend in Drupal. I'm not sure if in the Rules Link Component if I need to add the URL first then move to the Form page next (using Rules), or if that is completely an incorrect approach on my part and I need to use an API or whatever.

Any advice is very much appreciated. Thanks.

  • Welcome to Drupal Answers! Please add an explicit question. The purpose of Stack Exchange is not giving advices, but answering questions. – kiamlaluno Apr 4 '16 at 14:31
1

You need to have an entity reference field in your form and set it to reference nodes.

Normally, you would then build your link with the current node's Nid to fill the entity reference field on the next page.

http://example.com/node/add/article?field_previous_page=123

However, because you are using rules link, I guess you have to create a redirect to the form based on the current node replacement pattern available.

Or below is a solution if that doesn't work out.

If you really must use rules link and can't get normal methods to work, then Rules Session Variables would be an easy solution. It will give you actions to let you add the node's id into $_session.

Then when you the user saves the form, have another rule that checks if $_session exists and if so, take the Nid, fetch the node and then set the entity reference field with it.

So yeah, do you need to use rules link?

  • After numerous hours, none of this worked. I tried $session Rules which pasted the node ID, but I could not get it to paste into, say a Title field and besides it never copied the full Alias. Enity Prepopulate only gave either a full list of Nodes either Dropdown list or Auto Complete. Maybe after 5 years, Drupal is beyond me. )-: laughs crying! – Paul B May 2 '16 at 20:54
  • Did you try to build a link using tokens with the current NID? Can you paste what the link looks like? And did you enable entity reference prepopulate on a new entity reference field in that form? – Niall Murphy May 3 '16 at 2:43
  • Thanks for your reply. In all honesty, I'm not really bothered at this stage how the previous Node is related in the 2nd Node create (Application) form. Imagine the first Node being a "Musician Wanted" Advert Node, the reader (applicant) applies for that Role and the said 1st Nodes Advert Title is automatically encoded into the 2nd Node's apply Form Title field automatically, then a new Application Node is created from the said Form. Later, I can use modules like Relations to manage them, I'm not really bothered if I use Rules. I'm trying to learn. – Paul B May 3 '16 at 9:59
  • ...I did install Entity Reference Prepopulate module, but the field was showing a 'dropdown' list, but not in the Title field as I preferred, so I've left it for now. I'm really open to suggestions to resolve this as it's taking me really far too long. Thanks. – Paul B May 3 '16 at 9:59
  • 1
    Aha, here is an interesting use-case of that "Rules Session Variables" module ... PS: sorry I cannot upvote it any further (only 1 upvote allowed). – Pierre.Vriens Feb 25 '17 at 9:53

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.