2
/**
* Implementation of hook_token_values().
*/
function content_profile_token_token_values($type, $object = NULL, $options = array()) {
  $values = array();
  switch ($type) {
    case 'user':
      if (isset($object)) {
        $account = user_load(array('uid' => $object->uid));
      }
      else {
        global $user;
        $account = user_load(array('uid' => $user->uid));
      }


      $node_profile = content_profile_load('profile', $account->uid);
      $values['profile'] = ($node_profile->title) ? $node_profile->title : '';     


      break;
  }
  return $values;
}

/**
* Implementation of hook_token_list().
*/
function content_profile_token_token_list($type = 'all') {
  if ($type == 'user' || $type == 'all') {
    $tokens = array();
    $tokens['user']['profile'] = t('Profile title of authors content profile');

    return $tokens;
  }
}

I have created a module, and added a .info file as intended, but when I check the token list for a image field title I don't see any of the tokens implemented by my module.
What am I doing wrong?

UPDATED!!!

Now i see my token in imagefield token list, but it doesnt works == doesnt add content profile title for img...

2 Answers 2

1

It is not appearing because the ImageField module is using user tokens, for the image title, while your module is defining node tokens.
You can see this from the code in imagefield_widget.inc (imagefield_widget_settings_form()), which is the following one:

  $form['title_settings']['title_type'] = array(
    '#type' => 'select',
    '#title' => t('Input type'),
    '#options' => array(
      'textfield' => 'textfield',
      'textarea' => 'textarea'),
    '#default_value' => !empty($widget['title_type']) ? $widget['title_type'] : 'textfield',
    '#description' => t('Choose type of field to be displayed to the user.'),
  );
  $form['title_settings']['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Default Title text'),
    '#default_value' => !empty($widget['title']) ? $widget['title'] : '',
    '#description' => t('This value will be used as the image title by default.'),
    '#suffix' => theme('token_help', array('user')),
  );

The tokens you define in your module are node tokens, which are not shown when the code calls theme('token_help', array('user')).

1
  • So i should use 'user' instead of 'node' in my module? Could you throw an example for me, how to use that in my module. Commented Jul 6, 2011 at 3:59
0

A couple of checks.

You do have a module name, your not just putting '[mymodulename]' in the code.

Is your module enabled?

Have you cleared the cache?

If all of the above is true then you can start to put debug code in to make sure the correct values are being pulled.

1
  • all above is true of course. Commented Jul 6, 2011 at 3:57

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.