3

I'm using panels to override a nodes display page. I also want to use it to overide the edit and add page. The cck type I'm trying to add has a node reference field, this needs to be passed in through the url.

So far, I've add the panel varaint, added a context (node add form), and added the form to the "content" of the panel, All I need to figure out is how to pass the referencing node ID to the form. Does any one know how to do this?

1

This is an old question but there is an easier way with the Node Reference URL Widget module, which should work with Panels as well.

0

You can create your own menu callback using hook_menu (you need to do this from your custom module). Then from your custom callback you you can call whatever callback function is assigned to the different panel pages you have. In your custom callback, you will need to specify the path to whatever function panels is using in it's callback. Here's how your custom callback could look like:

<?php    
/**
 * The 1st %node argument represents the node you are editing.
 * The 2nd %node argument would represent the referencing node ID.
 */
$items['node/%node/%node/edit'] = array(
    'page callback' => 'mymodule_edit_node',
    'page arguments' => array(1,2),     

    // Other arguments ...

    // This includes the node_edit.inc file, needed for calling the page_manager_node_edit() function.
    'file' => 'node_edit.inc',
    'file path' => drupal_get_path('module', 'page_manager'). '/plugins/tasks',   );

/**
 * The callback above automatically converts $node_edit and $node_ref to node objects.
 */
function mymodule_edit_node($node_edit, $node_ref) {
  // Do something with $node_ref, like building a Form or storing it
  // statically in a function for later use.
  &drupal_static(__FUNCTION__, $node_ref);

  // page_manager_node_edit() is what Panels uses for rendering it's custom edit node page.
  return page_manager_node_edit($node_edit);
}

It's a little hard to figure out how your form is looking in that panel page, based on your description above, so I cannot give a concrete example of how to insert the node reference directly into the form. However most likely it would involve using one the hook_form_alter() or hook_form_FORM_ID_alter() functions. Using these you can retrieve the referenced node using the drupal_static() function or directly using arg():

<?php
// Retrieve from static cache:
$foo = &drupal_static(__FUNCTION__);

// Retrieve from URL:
$foo = arg(2)

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.