You are here

function imagecache_token_token_info_alter in Imagecache Token 7

Implements hook_token_info_alter().

File

./imagecache_token.module, line 29
Primary hook implementations for the Imagecache Token module.

Code

function imagecache_token_token_info_alter(&$data) {
  $fields = field_info_field_map();

  // Check to see which fields are supported.
  $supported = variable_get('imagecache_token_fields', array());
  $supported = array_filter($supported);
  foreach ($fields as $field_name => $field) {
    $field['field_name'] = $field_name;
    if ($field['type'] == 'image' || $field['type'] == 'file' || $field['type'] == 'media') {
      foreach ($field['bundles'] as $entity_type => $bundles) {
        foreach ($bundles as $bundle) {

          // For 'file' and 'media' field types, it's possible that some fields
          // won't actually contain images. In these scenarios, the fields must
          // be enabled on the settings page.
          if ($field['type'] == 'file' || $field['type'] == 'media') {
            $key = $field['type'] . ':' . $field['field_name'] . ':' . $entity_type . ':' . $bundle;
            if (empty($supported[$key])) {
              continue;
            }
          }
          $token_type = token_get_entity_mapping('entity', $entity_type);
          if (!empty($data['tokens'][$token_type][$field['field_name']])) {
            $data['tokens'][$token_type][$field['field_name']]['type'] = 'image-field';
          }
        }
      }
    }
  }
}