0

I have a content type 'school' and an entityform that's called 'contact'...

I would like the URL path for the contact form to be:

www.example.com/node/nid/contact

It's important that the node ID be passed in the link to the entityform in this format rather than:

www.mysite.com/eform/submit/contactform?some_custom_field=[nid]

so that people can share the contact form easily.

It's also important that the contact form be an entityform

Any pointers to set up my entityform url so that it reflects the NID of the content that linked to it?

I am trying to set up URL alias for the entityform but am having trouble setting up the NID as a wildcard.

EDIT for my helper module I have...(we can ignore the entityform part of my question because I'll probably re-build the form) ... I am trying to get the letter generator to appear at /node/%node/lettergen but the %node wildcard isn't working ...

function lettergen_menu() {
$items = array();
$items['node/%node/lettergen'] = array( 
'title' => 'Letter Generator', 
'description' => 'Generate a Letter'
'load arguments' => array(1),
'page arguments' => array('lettergen_form', 1),
'access callback' => TRUE,
);
return $items;
}

THIS WORKS

function lettergen_menu() {
$items['node/%node/lettergen'] = array(
'title' => 'Lettergen',
'description' => 'A form to mess around with.',
'page callback' => 'drupal_get_form',
'page arguments' => array('lettergen_form', 1),
'access callback' => TRUE,
);
return $items;
}

1 Answer 1

2

One of the option is:

  1. create a entity reference field in 'school' content type to reference associated contact form.

  2. write a helper module that adds a menu item node/%node/contact.

  3. Make sure access_callback check for your content type and return false for other node type to avoid any perf issue.

  4. In menu callback function, render the entity form to display.

Here is an example of "node/%node/something" pattern from token module.

/**
 * Implements hook_menu().
 */
function token_menu() {
  ...
  ...  

  $items['node/%node/devel/token'] = array(
      'title' => 'Tokens',
      'page callback' => 'token_devel_token_object',
      'page arguments' => array('node', 1),
       // 'node' => token_devel_token_object function gets a string 'node' as argument 1 
       // 1 => token_devel_token_object function gets a node object of node id given in url. for mode details refer https://api.drupal.org/api/drupal/modules!node!node.api.php/function/hook_load/7.
      'access arguments' => array('access devel information'),
      'type' => MENU_LOCAL_TASK,
      'file' => 'token.pages.inc',
      'weight' => 5,
    );


// page callback definition
/**
 * Menu callback; prints the available tokens and values for an object.
 */
function token_devel_token_object($entity_type, $entity) {
...
...
}
3
  • Thanks for your help. I have started on my helper module as you suggested. Can you help me with the code posted ... I can't figure out how to pass the %node wildcard so that my form appears at /node/%node/lettergen I'll mark as answered if you can point out when my code snippet is wrong, don't worry about the entityform stuff... Commented Jul 10, 2014 at 17:53
  • Updated code sample that gives some idea.
    – vijaycs85
    Commented Jul 10, 2014 at 18:09
  • Ok thanks I got it to work. Thanks for sticking with me. You might want to adjust the code you posted to reflect what worked for me, as I did not find it helpful. Nevertheless marked as answered. Thanks again. Commented Jul 10, 2014 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.