You are here

function emimage_widget_settings in Embedded Media Field 6.3

Same name and namespace in other branches
  1. 6 contrib/emimage/emimage.module \emimage_widget_settings()
  2. 6.2 contrib/emimage/emimage.module \emimage_widget_settings()

File

contrib/emimage/emimage.module, line 142
Embedded Image module is a handler for images hosted on an external site.

Code

function emimage_widget_settings($op, $widget) {
  switch ($op) {
    case 'form':
      $form = (array) module_invoke('emfield', 'emfield_widget_settings', 'form', $widget, 'emimage');
      if ($widget['type'] == 'emimage_textfields') {
        $link_options = array(
          EMIMAGE_LINK_NONE => t('No link'),
          EMIMAGE_LINK_CONTENT => t('Link to content'),
          EMIMAGE_LINK_PROVIDER => t('Link to provider'),
        );
        $width = variable_get('emimage_default_full_width', EMIMAGE_DEFAULT_FULL_WIDTH);
        $height = variable_get('emimage_default_full_height', EMIMAGE_DEFAULT_FULL_HEIGHT);
        $form['full'] = array(
          '#type' => 'fieldset',
          '#title' => t('Full size display settings'),
          '#description' => t('These settings control how this image is displayed in its full size, which defaults to @widthx@height. Note that if one of the dimensions is 0, then the image will be resized to be no larger than the other dimension.', array(
            '@width' => $width,
            '@height' => $height,
          )),
          '#collapsible' => true,
          '#collapsed' => false,
        );
        $form['full']['full_width'] = array(
          '#type' => 'textfield',
          '#title' => t('Full size display width'),
          '#default_value' => is_null($widget['full_width']) ? $width : $widget['full_width'],
          '#description' => t('The width of the image. It defaults to @width. Set it to 0 or blank if you want to leave the image at its original aspect ratio.', array(
            '@width' => $width,
          )),
        );
        $form['full']['full_height'] = array(
          '#type' => 'textfield',
          '#title' => t('Full size display height'),
          '#default_value' => is_null($widget['full_height']) ? $height : $widget['full_height'],
          '#description' => t('The height of the image. It defaults to @height. Set it to 0 or blank if you want to leave the image at its original aspect ratio.', array(
            '@height' => $height,
          )),
        );
        $full_link = variable_get('emimage_default_full_link', EMIMAGE_DEFAULT_FULL_LINK);
        $form['full']['full_link'] = array(
          '#type' => 'select',
          '#title' => t('Full size link'),
          '#description' => t("Where the image will link when displayed in its full size. 'Content' links to the content page, 'provider' links to the provider's image page, and 'none' displays the image with no link."),
          '#options' => $link_options,
          '#default_value' => is_null($widget['full_link']) ? $full_link : $widget['full_link'],
        );
        $width = variable_get('emimage_default_preview_width', EMIMAGE_DEFAULT_PREVIEW_WIDTH);
        $height = variable_get('emimage_default_preview_height', EMIMAGE_DEFAULT_PREVIEW_HEIGHT);
        $form['preview'] = array(
          '#type' => 'fieldset',
          '#title' => t('Image Preview Settings'),
          '#description' => t('These settings control how this image is displayed in its preview size, which defaults to @widthx@height. Note that if one of the dimensions is 0, then the image will be resized to be no larger than the other dimension.', array(
            '@width' => $width,
            '@height' => $height,
          )),
          '#collapsible' => true,
          '#collapsed' => false,
        );
        $form['preview']['preview_width'] = array(
          '#type' => 'textfield',
          '#title' => t('Image preview width'),
          '#default_value' => is_null($widget['preview_width']) ? $width : $widget['preview_width'],
          '#description' => t('The width of the image preview. It defaults to @width. Set it to 0 or blank if you want to leave the image at its original aspect ratio.', array(
            '@width' => $width,
          )),
        );
        $form['preview']['preview_height'] = array(
          '#type' => 'textfield',
          '#title' => t('Image preview height'),
          '#default_value' => is_null($widget['preview_height']) ? $height : $widget['preview_height'],
          '#description' => t('The height of the image preview. It defaults to @height. Set it to 0 or blank if you want to leave the image at its original aspect ratio.', array(
            '@height' => $height,
          )),
        );
        $preview_link = variable_get('emimage_default_preview_link', EMIMAGE_DEFAULT_PREVIEW_LINK);
        $form['preview']['preview_link'] = array(
          '#type' => 'select',
          '#title' => t('Preview size link'),
          '#description' => t("Where the image will link when displayed in its preview size. 'Content' links to the content page, 'provider' links to the provider's image page, and 'none' displays the image with no link."),
          '#options' => $link_options,
          '#default_value' => isset($widget['preview_link']) ? $widget['preview_link'] : $preview_link,
        );
        $width = variable_get('emimage_default_thumbnail_width', EMIMAGE_DEFAULT_THUMBNAIL_WIDTH);
        $height = variable_get('emimage_default_thumbnail_height', EMIMAGE_DEFAULT_THUMBNAIL_HEIGHT);
        $form['tn'] = array(
          '#type' => 'fieldset',
          '#title' => t('Thumbnail'),
          '#description' => t('When displayed as a thumbnail, these settings control the image returned. The default size for thumbnails is @widthx@height. Note that if one of the dimensions is 0, then the image will be resized to be no larger than the other dimension.', array(
            '@width' => $width,
            '@height' => $height,
          )),
          '#collapsible' => true,
          '#collapsed' => false,
        );
        $form['tn']['thumbnail_width'] = array(
          '#type' => 'textfield',
          '#title' => t('Image thumbnail width'),
          '#default_value' => is_null($widget['thumbnail_width']) ? $width : $widget['thumbnail_width'],
          '#description' => t('The width of the image thumbnail. It defaults to @width. Set it to 0 or blank if you want to leave the image at its original aspect ratio.', array(
            '@width' => $width,
          )),
        );
        $form['tn']['thumbnail_height'] = array(
          '#type' => 'textfield',
          '#title' => t('Image thumbnail height'),
          '#default_value' => is_null($widget['thumbnail_height']) ? $height : $widget['thumbnail_height'],
          '#description' => t('The height of the image thumbnail. It defaults to @height. Set it to 0 or blank if you want to leave the image at its original aspect ratio.', array(
            '@height' => $height,
          )),
        );
        $thumb_link = variable_get('emimage_default_thumbnail_link', EMIMAGE_DEFAULT_THUMBNAIL_LINK);
        $form['tn']['thumbnail_link'] = array(
          '#type' => 'select',
          '#title' => t('Image thumbnail link'),
          '#description' => t("Where the image will link when displayed as a thumbnail. 'Content' links to the content page, 'provider' links to the provider's image page, and 'none' displays the image with no link."),
          '#options' => $link_options,
          '#default_value' => is_null($widget['thumbnail_link']) ? $thumb_link : $widget['thumbnail_link'],
        );
      }
      return $form;
    case 'validate':
      if ($widget['type'] == 'emimage_textfields') {
        if (!is_numeric($widget['full_width']) || intval($widget['full_width']) != $widget['full_width'] || $widget['full_width'] < 0) {
          form_set_error('full_width', t('"Full size width" must be an integer.'));
        }
        if (!is_numeric($widget['full_height']) || intval($widget['full_height']) != $widget['full_height'] || $widget['full_height'] < 0) {
          form_set_error('full_height', t('"Full size height" must be an integer.'));
        }
        if (!is_numeric($widget['preview_width']) || intval($widget['preview_width']) != $widget['preview_width'] || $widget['preview_width'] < 0) {
          form_set_error('preview_width', t('"Preview width" must be an integer.'));
        }
        if (!is_numeric($widget['preview_height']) || intval($widget['preview_height']) != $widget['preview_height'] || $widget['preview_height'] < 0) {
          form_set_error('preview_height', t('"Preview height" must be an integer.'));
        }
        if (!is_numeric($widget['thumbnail_width']) || intval($widget['thumbnail_width']) != $widget['thumbnail_width'] || $widget['thumbnail_width'] < 0) {
          form_set_error('thumbnail_width', t('"Thumbnail width" must be an integer.'));
        }
        if (!is_numeric($widget['thumbnail_height']) || intval($widget['thumbnail_height']) != $widget['thumbnail_height'] || $widget['thumbnail_height'] < 0) {
          form_set_error('thumbnail_height', t('"Thumbnail height" must be an integer.'));
        }
      }
      break;
    case 'save':
      if ($widget['widget_type'] == 'emimage_textfields') {
        $columns = array(
          'full_width',
          'full_height',
          'full_link',
          'preview_width',
          'preview_height',
          'preview_link',
          'thumbnail_width',
          'thumbnail_height',
          'thumbnail_link',
        );
        $columns = array_merge($columns, module_invoke('emfield', 'emfield_widget_settings', 'save', $widget, 'emimage'));
        return $columns;
      }
      break;
  }
}