0

Assume a content type with two user fields, being a description and a file. Assume that a few content items, or nodes, have been created that are based on this content type.

Description Image Joe Brown www.images.com/picture_of_JoeBrown Joanna White www.images.com/picture_of_JoannaWhite Jeremy Green www.images.com/picture_of_JeremyGreen etc

Easy enough to create a menu item that points at the node. Once the user has opened the node they can click on the image's URL and retrieve the image.

Easy enough to create an "external link" that points directly at the image and jumps straight to it. However the external link's address is static.

How does one create a menu item the jumps directly to the image that is currently stored in the Drupal node/content without an intermediate step?

In this example, I need to append the name of the field that contains the image url to the menu node address so that the system will show the person's current image with a single click from the menu without an intervening node/content display.

This seems like it should be easy, but I can't see it......

1

The quickest might be with a MENU_LOCAL_TASK in a custom module, e.g.:

function YOURMODULE_menu() {

  $items=array();

  $items['node/%node/avatar'] = array (
    'title' => 'Avatar',
    'page callback' => 'YOURMODULE_node_avatar',
    'page arguments' => array(1),
    'access callback' => TRUE,
    'weight' => 64,
    'type' => MENU_LOCAL_TASK,
  );

  return $items;

}

function YOURMODULE_node_avatar($node) {
  // drupal_goto($node->field_avatar[0]['filepath']); // Drupal 6
  drupal_goto($node->field_avatar[LANGUAGE_NONE][0]['filepath']); // Drupal 7 (I think :)
}

which would create an Avatar tab for you that when clicked on would display the image in field_avatar. Obviously you'd have to change that up to your exact field (and I think I got the D7 language stuff right in there if you are on D7).

It could also be called directly, e.g. www.YOURHOST.com/node/1/avatar would display the avatar of node with nid 1. If this is going to be how you access it, you could change MENU_LOCAL_TASK to MENU_CALLBACK and then the Avatar tab wouldn't show up on the page.

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.