You are here

function download_field_widget_form in Download 7.2

Same name and namespace in other branches
  1. 7 download.module \download_field_widget_form()

Implements hook_field_widget_form().

File

./download.module, line 155
Handles module administration and download link

Code

function download_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  $value = isset($items[$delta]['download_fields']) ? $items[$delta]['download_fields'] : '';
  $default_label = isset($items[$delta]['download_label']) ? $items[$delta]['download_label'] : '';
  $default_value = is_array($value) ? $value : explode(';', $value);
  $widget = $element;
  $widget['#delta'] = $delta;
  switch ($instance['widget']['type']) {
    case 'download_link_widget':
      $options = array();
      $fields = field_info_fields();
      $allowed_types = array(
        'file',
        'image',
      );
      foreach ($fields as $field_name => $field) {
        $used_bundles = array();
        foreach ($field['bundles'] as $bundles) {
          $used_bundles = array_merge($used_bundles, $bundles);
        }
        if (in_array($instance['bundle'], $used_bundles)) {
          if (in_array($field['type'], $allowed_types)) {
            $options[$field['field_name']] = $field['field_name'];
          }
        }
      }
      $widget += array(
        '#type' => 'checkboxes',
        '#title' => 'Select fields to compress.',
        '#options' => $options,
        '#default_value' => $default_value,
      );
      $label = array(
        '#type' => 'textfield',
        '#title' => 'Text to display',
        '#delta' => $delta,
        '#default_value' => $default_label,
      );
      break;
  }
  $element['download_fields'] = $widget;
  if (isset($label)) {
    $element['download_label'] = $label;
  }
  return $element;
}