1

I want create page for issues of newspaper. Title of the issue page must contain the issue number, date of publishing and size of newspaper file in MB.

I implemented number and date in title with Automatic Entity Labels and Token modules. But how I can place in title size of the uploaded file?

I tried to use custom module:

/**
* Implements hook_token_info().
*/
function mytokens_token_info() {
$node_tokens['field_file']['size'] = array(
  'name' => t('File size'),
  'description' => t('File size'),
);
$node_tokens['field_file']['size']['mbytes'] = array(
  'name' => t('In MB'),
  'description' => t('File size in MB'),
);
return array(
  'tokens' => array(
  'node' => $node_tokens,
  ),
);
}

/**
 * Implements hook_tokens().
 */
function mytokens_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();

if ($type == 'node' && !empty($data['node'])) {
$node = $data['node'];

foreach ($tokens as $name => $original) {
  if ($name == 'mbytes') {
    $replacements[$original] = $node->field_file['und'][0]['filesize']/(1024*1024);
  }
}
}

  return $replacements;
}

But my tokens don't shows in the token tree and nothing replacements occur.

0

Install Token and you can use [file:size] in your title to fetch file size. Here is the list of all file tokens you can choose from.

| improve this answer | |

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.