You are here

imagefield_tokens.module in ImageField Tokens 5

File

imagefield_tokens.module
View source
<?php

/**
 * @file
 */

/**
 * Implementation of hook_form_alter().
 */
function imagefield_tokens_form_alter($form_id, &$form) {
  if (isset($form['module']) && $form['module']['#value'] == 'imagefield') {
    $ifp = array(
      'alt' => array(
        'title' => 'ALT text',
        'form_path' => &$form['widget']['alt_settings'],
      ),
      'title' => array(
        'title' => 'Title text',
        'form_path' => &$form['widget']['title_settings'],
      ),
    );
    foreach ($ifp as $name => &$field) {
      unset($field['form_path'][$name]['#suffix']);
      $field['form_path'][$name . '_tokens'] = array(
        '#type' => 'fieldset',
        '#title' => t('!title replacement patterns', array(
          '!title' => $field['title'],
        )),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#description' => theme_filefield_paths_token_help(),
      );
    }
  }
}

/**
 * Implementation of hook_filefield_paths_process_file().
 */
function imagefield_tokens_filefield_paths_process_file($new, &$file, $settings, $node, $update) {
  if ($file['widget'] == 'image') {
    $orig = array(
      'alt' => $file['field']['alt'],
      'title' => $file['field']['title'],
    );
    $file['field']['alt'] = filefield_paths_process_string($file['field']['alt'], 'node', $node);
    $file['field']['alt'] = filefield_paths_process_string($file['field']['alt'], 'field', array(
      0 => $file['field'],
    ));
    $file['field']['title'] = filefield_paths_process_string($file['field']['title'], 'node', $node);
    $file['field']['title'] = filefield_paths_process_string($file['field']['title'], 'field', array(
      0 => $file['field'],
    ));
  }
}

Functions

Namesort descending Description
imagefield_tokens_filefield_paths_process_file Implementation of hook_filefield_paths_process_file().
imagefield_tokens_form_alter Implementation of hook_form_alter().