Great module. I love the workflow and the avoidance of a modal solution.
I would like to pass query params to the node add page of my referenced node. Here is my use case:
Organization - node type, using organic groups this is a group type
Contact - node type, using organic groups this is a group post.
If I want to create a contact and auto-populate the group, I need to pass the group id on the command line:
http://example.com/node/add/contact?og_group_ref=1234
OG7 2.x uses entityreference_prepopulate (http://drupal.org/project/entityreference_prepopulate) to fill in the field value from the query param.
In Organization, I have a node reference field called Primary Contact which is a single value field referencing Contact nodes.
I would like to use nodeconnect to add contacts to Primary Contact from the Organization node edit form. This means passing query params to the node add page.
To do this, I added my own custom submit handler to the add button generated by nodeconnect:
function mymodule_form_organization_node_form_alter(&$form, &$form_state) {
// Only add group gid to edit forms (add forms have no nid/gid)
if (isset($form['nid']['#value'])) {
$org_gid = $form['nid']['#value'];
$form['field_primary_contact'][LANGUAGE_NONE][0]['add_nodeconnect__field_cis_org_channel_1_0']['#submit'][] = 'mymodule_add_group_flag_submit';
}
}
Then, in this function, I updated $form_state['redirect'] with my query value:
function mymodule_add_group_flag_submit(&$form, &$form_state) {
$url = $form_state['redirect'];
$form_state['redirect'] = array(
$url,
array(
'query' => array(
'og_group_ref' => $form['nid']['#value'],
)
),
);
}
This is almost working, but not quite. Because there is a 2nd drupal_goto() in the mix.
What I did here successfully adds the query string to the call made to admin/nodeconnect/add/%. So the page request is:
http://example.com/admin/connect/add/nodeconnect_cache_id?og_group_ref=1234
Unfortunately, there is another drupal_goto() in the callback, nodeconnect_add():
function nodeconnect_add($cache_id) {
$content = array();
$cache = cache_get($cache_id);
$field = field_info_field($cache->data['field']);
$acceptable_types = $field['settings']['referenceable_types'];
foreach (system_admin_menu_block(menu_get_item("node/add")) as $key => $item) {
$type = str_replace("-", '_', str_replace("node/add/", "", $item['path']));
if (isset($acceptable_types[$type]) && $acceptable_types[$type]) {
$item['href'] = $item['href'] . "/$cache_id";
$content[$key] = $item;
}
}
if (sizeof($content) == 1) {
$item = array_pop($content);
drupal_goto($item['href']);
}
$output = theme('node_add_list', array('content' => $content));
$output .= l(t('Cancel'), "admin/nodeconnect/return/$cache_id");
return $output;
}
Because of the way this drupal_goto() is called in this module, I can't think of a way to get the query string back in.
So I think I need to patch nodeconnect to get this to work. I think the way to do this would be to change nodeconnect_add() so that if there were any query params passed to that page request, they will be preserved and repassed to drupal_goto(). I don't know if this would screw up interactions with passed destination params though.
Would you accept such a patch? Is there a better way to go with this or am I missing anything?
Comments
Comment #1
dtarc commentedThis is a duplicate of #1529056: Allow for the passing of query params to node/add (compatibility with organic groups)