Skip directly to content

Pass nid as argument in URL path when opening node add form in a ctools modal frame

on May 11th, 2012 at 7:21:49 AM

Here is the best tutorial I found in the internet to open a "node add" form in a Ctools modal frame (with Drupal 7):

What we want to do is pass an argument through the Ctools modale frame URL path and inject it in a Entity/Node reference field. Before coding we need to install one of the following module: Entityreference prepopulate or Node Reference URL Widget. What both modules are doing is checking if a node NID is present in the URL path from your browser and if so, it will be passed to the form you are opening to prepopulate a field.
To make it appened, the module needs to get the node NID from an "add node" link you have in a custom block, for example. When you need that this link open in a Ctools modale frame, you'll probably have use the ctools_modal_text_button function.

From the aboved mentioned tutorial, in the sidebar_link() function we will change:

= ctools_modal_text_button(t('Submit an event'), 'create/nojs/public-event', 'public-event');


= arg(1);
// get the node nid from the URL
  $link_modal = ctools_modal_text_button(t('Submit an event'), 'create/nojs/public-event?field_you_want_to_prepopulate='.$arg1, 'public-event');
$output = str_replace (array('%3F', '%3D'), array('?', '='), $link_modal);


Comments's picture

I am really thankful to the holder of this website who has shared this fantastic piece of writing at at this time.

Winston Degroat's picture

Wow, superb blog structure! How long have you ever been blogging for?
you make blogging glance easy. The entire glance of your site
is excellent, let alone the content!

Johna634's picture

Hi there. Simply just planned to request a simple dilemma. ebedkefackec

Post new comment