Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
After a user add new content using the prepopulate link, on submit, returned user to the referenced entity display instead of the newly added node view. See attached node edit screen shot for a reference field using the Node URL Widget for the References module.
Comment | File | Size | Author |
---|---|---|---|
#12 | destination_ignored-1469962-12.patch | 3.44 KB | jastraat |
#10 | destination_ignored-1469962.patch | 1.67 KB | jastraat |
Node-URl-Widget-return-path-option.png | 148.23 KB | rwilson0429 |
Comments
Comment #1
amitaibuI'm ok with adding this. A patch would get it quicker than a screenshot ;)
Comment #2
rwilson0429 CreditAttribution: rwilson0429 commentedThanks Amitaibu. I'm so sorry that I am not a coder. Otherwise, I would have definitely provided a patch. I'm trying to learn though. It (coding) seem so damn complicated to me. From where I sit, you guys are genius. Hopefully, I'll begin to grasp it one day and be able to contribute patches.
Comment #3
rokr CreditAttribution: rokr commentedWorkaround: you can do this with rules very easy.
Comment #4
Nchase CreditAttribution: Nchase commentedYeah, rules might work on a simple setup.
The desitination should be configurable from the field itself, or the ?destination=node/nid parameter should work...
Comment #5
amitaibu> The desitination should be configurable from the field itself
I agree. How about a patch? :)
Comment #6
Nchase CreditAttribution: Nchase commented:) we have to check the old url widget and get familiar with the prepopulate module. give us some time :)
Comment #7
trailrunner CreditAttribution: trailrunner commentedAs far as the Rules workaround, can you explain that a bit more? I'm just wondering how you set up Rules to do so.
Thanks!
Comment #8
rwilson0429 CreditAttribution: rwilson0429 commentedI was able to use drupal_get_destination() to redirect the user to the referenced entity. According to the api documentation:
Entity Reference Prepopulate requires a link that looks something like this: node/add/article?[field_ref]=[id]. So, a link to add new content and prepopulate the entity reference field would look something like:
<a href="/node/add/[YOUR-CONTENT-TYPE-MACHINE-NAME]?[YOUR-ER-FIELD]=[nid]">Add a [YOUR-CONTENT-TYPE]</a>
Where [YOUR-ER-FIELD] is the name of the entity reference field and [nid] is the nid of the entity being referenced.
The entity reference prepopulate parameter and the drupal_get_destination() function can be used together to prepopulate the ER field and return the user to the referenced entity after completing the node/add/[content-type] form. This can be accomplished with Views and EVA (Entity Views Attach) modules.
Assuming Views module is already installed, install and enable the EVA module.
Create a View with an Entity Content display of child entities (for example, images) and configure the Entity Content display Settings as follows:
Entity content settings
Entity type: Node
Bundles: [THE-ENTITY-TYPE-BEING-REFERENCED]
Arguments: id
Contextual filters
Content: [Your-ENTITY-REFERENCE-FIELD] (configure the filter and validate by setting the Filter value format to 'Node ID')
Relationships
Content entity referenced from [YOUR-REFERENCE-FIELD] (this relationship is used to get the nid of the referenced entity. Add the content nid to your View field list and use this relationship)
In the View's Header or Footer, add a Global Text Area and set the text filter to PHP.
Insert the code below
Now when you are viewing a parent content type, you will have a link to add a child content type. Clicking the link should take you to the node/add form for the child content and the entity reference field should be prepopulated. When you save the child content, you should be redirected to the the parent.
I'm sure this could be accomplished in a more elegant manner, but it worked for me.
Comment #9
Jason Dean CreditAttribution: Jason Dean commentedI worked around this using a Rule with these components:
This means the redirect happens even if prepopulate isn't used (e.g. the user manually adds new content) but that didn't matter in my use case.
Comment #10
jastraat CreditAttribution: jastraat commentedThis may be partially a bug. In looking at entityreference_prepopulate_create_node_links(), there is a parameter for $destination, but the variable is never used in the actual function. Instead, drupal_get_destination() is used.
Also, seeing the created post after node add is the default way drupal operates, so it seems like there should be an option to not append a destination parameter.
I've attached a patch that changes the entityreference_prepopulate_create_node_links() function to actually use the $destination parameter passed. The default behavior remains the same, but with this patch it is possible to set a custom destination or no destination at all.
Comment #11
jastraat CreditAttribution: jastraat commentedComment #12
jastraat CreditAttribution: jastraat commentedHere's a second patch that incorporates the changes to entityreference_prepopulate_create_node_links() to allow passing a destination parameter along with a small change to the content_type ctools plugin to give the option to not append a destination parameter.
Comment #13
jastraat CreditAttribution: jastraat commented@Amitaibu any chance you could review the attached patch?
Comment #14
tory-w CreditAttribution: tory-w as a volunteer commented@ Jason Dean, thank you. Your solution worked great! I tried the patches and they didn't work for me. But, this simple Rule did!
Comment #15
AnybodyNeeds reroll against latest 7.x-1.x-dev! Sorry.