You are here

function imagefield_widget_settings in ImageField 5.2

Same name and namespace in other branches
  1. 5 imagefield.module \imagefield_widget_settings()
  2. 6.3 imagefield.module \imagefield_widget_settings()

Implementation of hook_widget_settings().

File

./imagefield.module, line 414
Defines an image field type. imagefield uses content.module to store the fid, and the drupal files table to store the actual file data.

Code

function imagefield_widget_settings($op, $widget) {
  switch ($op) {
    case 'callbacks':
      return array(
        'default value' => CONTENT_CALLBACK_CUSTOM,
      );
    case 'form':
      $form = array();
      $form['max_resolution'] = array(
        '#type' => 'textfield',
        '#title' => t('Maximum resolution for Images'),
        '#default_value' => $widget['max_resolution'] ? $widget['max_resolution'] : 0,
        '#size' => 15,
        '#maxlength' => 10,
        '#description' => t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 for no restriction. If a larger image is uploaded, it will be resized to reflect the given width and height.'),
      );
      $form['max_filesize'] = array(
        '#type' => 'textfield',
        '#title' => t('Maximum filesize for Images'),
        '#default_value' => $widget['max_filesize'] ? $widget['max_filesize'] : 0,
        '#size' => 6,
        '#description' => t('The maximum allowed image file size expressed in kilobytes. Set to 0 for no restriction.'),
      );
      $form['max_number_images'] = array(
        '#type' => 'textfield',
        '#title' => t('Maximum number of images'),
        '#default_value' => $widget['max_number_images'] ? $widget['max_number_images'] : 0,
        '#size' => 4,
        '#description' => t('The maximum number of images allowed. Set to 0 for no restriction. This only applies if multiple values are enabled.'),
      );
      $form['image_path'] = array(
        '#type' => 'textfield',
        '#title' => t('Image path'),
        '#default_value' => $widget['image_path'] ? $widget['image_path'] : '',
        '#description' => t('Optional subdirectory within the "%dir" directory where images will be stored. Do not include trailing slash.', array(
          '%dir' => variable_get('file_directory_path', 'files'),
        )),
      );
      if (function_exists('token_replace')) {
        $form['image_path']['#description'] .= ' ' . t('You can use the following tokens in the image path.');
        $form['image_path']['#suffix'] = theme('token_help', 'user');
      }
      $form['file_extensions'] = array(
        '#type' => 'textfield',
        '#title' => t('Permitted upload file extensions.'),
        '#default_value' => $widget['file_extensions'] ? $widget['file_extensions'] : 'jpg jpeg png gif',
        '#size' => 64,
        '#maxlength' => 64,
        '#description' => t('Extensions a user can upload to this field. Seperate extensions with a space and do not include the leading dot.'),
      );
      $form['custom_alt'] = array(
        '#type' => 'checkbox',
        '#title' => t('Enable custom alternate text'),
        '#default_value' => $widget['custom_alt'] ? $widget['custom_alt'] : 0,
        '#description' => t('Enable custom alternate text for images. Filename will be used if not checked.'),
      );
      $form['custom_title'] = array(
        '#type' => 'checkbox',
        '#title' => t('Enable custom title text'),
        '#default_value' => $widget['custom_title'] ? $widget['custom_title'] : 0,
        '#description' => t('Enable custom title text for images. Filename will be used if not checked.'),
      );
      return $form;
    case 'validate':

      // strip slashes from the beginning and end of $widget['image_path']
      $widget['image_path'] = trim($widget['image_path'], '\\/');
      form_set_value(array(
        '#parents' => array(
          'image_path',
        ),
      ), $widget['image_path']);
      break;
    case 'save':
      return array(
        'max_resolution',
        'max_filesize',
        'max_number_images',
        'image_path',
        'file_extensions',
        'custom_alt',
        'custom_title',
      );
  }
}