1.20.x image.tokens.inc image_token_info_alter(&$data)

Implements hook_token_info_alter().

File

modules/image/image.tokens.inc, line 292
Builds placeholder replacement tokens for image styles.

Code

function image_token_info_alter(&$data) {
  $fields = field_info_field_map();
  $entity_info = entity_get_info();

  // Check to see which fields are supported.
  $supported_fields = _image_token_get_image_fields();
  $supported_fields = array_filter($supported_fields);

  foreach ($fields as $field_name => $field) {
    $field['field_name'] = $field_name;
    if ($field['type'] == 'image' || $field['type'] == 'file') {
      foreach ($field['bundles'] as $entity_type => $bundles) {
        foreach ($bundles as $bundle) {
          // For 'file' 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') {
            $key = $field['type'] . ':' . $field['field_name'] . ':' . $entity_type . ':' . $bundle;
            if (empty($supported_fields[$key])) {
              continue;
            }
          }
          $token_type = $entity_info[$entity_type]['token type'];

          if (!empty($data['tokens'][$token_type][$field['field_name']])) {
            $data['tokens'][$token_type][$field['field_name']]['type'] = 'image-field';
          }
        }
      }
    }
  }
}