You are here

function imagefield_focus_widget_process in ImageField Focus 6

Element #process callback function.

1 string reference to 'imagefield_focus_widget_process'
imagefield_focus_elements in ./imagefield_focus.module
Implementation of hook_elements().

File

./imagefield_focus.module, line 96
Written by Henri MEDOT <henri.medot[AT]absyx[DOT]fr> http://www.absyx.fr

Code

function imagefield_focus_widget_process($element, $edit, &$form_state, $form) {
  static $settings_added;
  $item = $element['#value'];
  $field_name = $element['#field_name'];
  $field = $form['#field_info'][$field_name];
  if ($field['widget']['focus']) {
    $path = drupal_get_path('module', 'imagefield_focus');
    drupal_add_js($path . '/imgfocus/jquery.imgfocus.min.js');
    drupal_add_js($path . '/imagefield_focus.js');
    drupal_add_css($path . '/imgfocus/jquery.imgfocus.css');
    drupal_add_css($path . '/imagefield_focus.css');
    $element['data']['focus_rect'] = array(
      '#type' => 'textfield',
      '#title' => t('Focus rectangle'),
      '#value' => isset($item['data']['focus_rect']) ? $item['data']['focus_rect'] : '',
      '#description' => t('The important portion of the image to set focus to and that should <strong>never</strong> be cut. It is recommended to keep it as small as possible for best results.'),
      '#attributes' => array(
        'class' => 'imagefield-focus focus-rect',
      ),
    );
    $element['data']['crop_rect'] = array(
      '#type' => 'textfield',
      '#title' => t('Crop rectangle'),
      '#value' => isset($item['data']['crop_rect']) ? $item['data']['crop_rect'] : '',
      '#description' => t('When set, the portions of the image outside this area will <strong>always</strong> be cut out.'),
      '#attributes' => array(
        'class' => 'imagefield-focus crop-rect',
      ),
    );
    if (!isset($settings_added[$field_name])) {
      $settings_added[$field_name] = TRUE;
      list($w, $h) = explode('x', $field['widget']['focus_min_size']);
      $settings = array(
        'imagefield_focus' => array(
          $field_name => array(
            'min_width' => intval($w),
            'min_height' => intval($h),
            'lock_ratio' => !empty($field['widget']['focus_lock_ratio']),
          ),
        ),
      );
      drupal_add_js($settings, 'setting');
    }
    if (isset($element['preview']) && $item['fid'] != 0 && ($info = getimagesize(file_create_path($item['filepath'])))) {
      $element['data']['focus_box'] = array(
        '#value' => '<div class="imagefield-focus focus-box"><img src="' . file_create_url($item['filepath']) . '" alt="' . $info[0] . 'x' . $info[1] . '" style="display:none;" /></div>',
      );
    }
  }
  return $element;
}