You are here

function iss_field_widget_form in Image Style Selector 7

Implements hook_field_widget_form().

File

./iss.module, line 158
Image Style Selector field.

Code

function iss_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  $image_styles = array();

  // Show the label to the user (instead of the machine name).
  // NB: this also removes styles that aren't valid selections anymore (e.g.,
  // image style that is deleted).
  foreach ($instance['settings']['image_styles'] as $machine_name) {
    $image_style = image_style_load($machine_name);
    $image_styles[$machine_name] = $image_style['label'];
  }

  // Set general properties that all widgets have in common.
  $element['image_style'] = array(
    '#title' => t('Image style'),
  );
  switch ($instance['widget']['type']) {
    case 'iss_widget_radios':
      $element['image_style'] += array(
        '#type' => 'radios',
        '#options' => $image_styles,
        '#default_value' => isset($items[$delta]['image_style']) ? $items[$delta]['image_style'] : NULL,
      );
      break;
    case 'iss_widget_select':
      $element['image_style'] += array(
        '#type' => 'select',
        '#options' => $image_styles,
        '#default_value' => isset($items[$delta]['image_style']) ? $items[$delta]['image_style'] : NULL,
        '#multiple' => FALSE,
      );
      break;
  }
  return $element;
}