1

My site allows users to create a "booking request" node related to a "vehicle" node. I use an Entity Reference to connect the two by prepopulating a "Vehicle" field on the "booking request" node via a string in the URL:

http://example.com/vechiclename=&overlay=node/add/booking%3Ffield_vehicle%3D84

I would like to display a views block on this overlaid page with more info from the related vehicle. As you can see, the NID of the vehicle is in the URL (84), but I don't know how to target it.

I'm familiar with grabbing a path component from the URL, but it's the &field_vehicle=84 that is new to me. Any ideas?

1

I have never added a views block into the admin overlay (trying to get a parameter from the URL form the views block). But this is how I would approach the problem.

In your view, pick the 'Block' display. Add a contextual filter for the field that is referencing (Vehicle). Expand 'When the filter is not available'. Pick the option PHP Code. User the following code:

return (isset($_GET['field_vehicle'])) ? $_GET['field_vehicle'] : 'all';

I am using 'all' as fallback assuming that you will show everything if a value isn't available. But I guess you can use FALSE if you want it empty.

Save it. Add the block into your overlay/admin theme. Check if it works...

Best regards.

| improve this answer | |
  • Thanks for your reply. I tried your method, but no result. I think this does not work because the node has not yet been saved, and field_vehicle is not yet set (though a value has been prepopulated into the form). Thoughts? – Steven Dunwoody Aug 16 '13 at 18:32
  • I will run some tests locally and see if I can get this working. – Marcos Buarque Aug 16 '13 at 19:08
  • Hey, Steven, I have just set this solution locally (sorry for the delay) and it works! Don't forget you must add your Views block (the block we have prepared) into your admin theme. This is very important. Are you using something like SEVEN as admin theme? If you are, you have to go to the blocks administration section, click on the SEVEN tab and add the new Views block to the content region. When setting the block on Views, add a message for no results. That way you can see if your filter is working -- or not. If you don't get the empty message, means the block isn't properly set. – Marcos Buarque Aug 17 '13 at 11:02
  • I have my block properly configured (it displays without a contextual filter). I also got it to show "all" with the filter in place (displayed the first node's info on other nodes) when I changed "field_vehicle" to "field_vehicle[und]". I still cannot seem to pass the correct value. Maybe it's something about the format of the Entity Reference field? When I use the autocomplete widget for that field, I see "Name (NID)" in the field. If I use dropdown, I see "Name", but "NID" is the value set when I inspect the HTML. In what format does this PHP return the reference? – Steven Dunwoody Aug 17 '13 at 16:24
  • Steven, the form interface for autocomplete entity reference fields actually displays 'term name (nid)' but don't worry, this won't affect your results. Did you set the filter exactly as suggested (PHP code with the code above)? $_GET['field_vehicle'] should grab 'field_vehicle' from the URL. I am running out of ideas. – Marcos Buarque Aug 18 '13 at 11:52

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.