You are here

function imagefield_extended_widget_settings_alter in ImageField Extended 6.4

Implementation of hook_widget_settings_alter().

File

./imagefield_extended.module, line 107
Insert additional fields into a FileField / ImageField data array.

Code

function imagefield_extended_widget_settings_alter(&$settings, $op, $widget) {

  // Apply to all FileFields by default, we can remove specific cases latter.
  $widget_types = _content_widget_types();

  // On save, type could be FileField with widget_type containing the info we want.
  $widget_type = isset($widget['widget_type']) ? $widget['widget_type'] : $widget['type'];
  if (empty($widget_types[$widget_type]['field types'])) {
    return;
  }
  if (!in_array('filefield', $widget_types[$widget_type]['field types'])) {
    return;
  }
  $extended_fields = _imagefield_extended_fields();
  $ife_textfields = $extended_fields['textfields'];
  $ife_workflow_checkboxes = $extended_fields['checkboxes'];
  switch ($op) {
    case 'form':
      $weight = 12;
      foreach ($ife_textfields as $textfield => $title) {
        $title = check_plain($title);
        $settings[$textfield . '_settings'] = array(
          '#type' => 'fieldset',
          '#title' => t('!field text settings', array(
            '!field' => drupal_ucfirst($title),
          )),
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
          '#weight' => $weight++,
        );
        $settings[$textfield . '_settings']['custom_' . $textfield] = array(
          '#type' => 'checkbox',
          '#title' => t('Enable custom !field text', array(
            '!field' => $title,
          )),
          '#default_value' => !empty($widget['custom_' . $textfield]) ? $widget['custom_' . $textfield] : 0,
          '#description' => t('Enable user input !field text for files or images.', array(
            '!field' => $title,
          )),
        );
        $settings[$textfield . '_settings']['custom_' . $textfield . '_required'] = array(
          '#type' => 'checkbox',
          '#title' => t('Required'),
          '#default_value' => empty($widget['custom_' . $textfield . '_required']) ? 0 : 1,
        );
        $settings[$textfield . '_settings']['custom_' . $textfield . '_style'] = array(
          '#type' => 'radios',
          '#title' => t('Text field style', array(
            '!field' => $title,
          )),
          '#default_value' => !empty($widget['custom_' . $textfield . '_style']) ? $widget['custom_' . $textfield . '_style'] : 'textfield',
          '#options' => $extended_fields['textfield options'],
        );
        $settings[$textfield . '_settings'][$textfield . '_help'] = array(
          '#type' => 'textfield',
          '#title' => t('!field help or description text', array(
            '!field' => $title,
          )),
          '#default_value' => !empty($widget[$textfield . '_help']) ? $widget[$textfield . '_help'] : '',
          '#description' => t('This value will be used for !field text description field.', array(
            '!field' => $title,
          )),
        );
        $settings[$textfield . '_settings'][$textfield] = array(
          '#type' => 'textfield',
          '#title' => t('Default !field text', array(
            '!field' => $title,
          )),
          '#default_value' => !empty($widget[$textfield]) ? $widget[$textfield] : '',
          '#description' => t('This value will be used for !field text by default.', array(
            '!field' => $title,
          )),
        );
      }
      $settings['workflow_settings'] = array(
        '#type' => 'fieldset',
        '#title' => t('Workflow settings'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#access' => !empty($ife_workflow_checkboxes),
        '#weight' => $weight++,
      );
      foreach ($ife_workflow_checkboxes as $checkbox => $title) {
        $title = check_plain($title);
        $settings['workflow_settings']['workflow_' . $checkbox] = array(
          '#type' => 'checkbox',
          '#title' => t('Enable !field checkbox', array(
            '!field' => $title,
          )),
          '#default_value' => empty($widget['workflow_' . $checkbox]) ? 0 : 1,
          '#description' => t('Enable user input !field checkbox for files or images.', array(
            '!field' => $title,
          )),
        );
      }
      break;
    case 'save':
      $if_settings = array();
      foreach (array_keys($ife_textfields) as $textfield) {
        $if_settings[] = $textfield;
        $if_settings[] = $textfield . '_help';
        $if_settings[] = 'custom_' . $textfield;
        $if_settings[] = 'custom_' . $textfield . '_style';
        $if_settings[] = 'custom_' . $textfield . '_required';
      }
      foreach (array_keys($ife_workflow_checkboxes) as $checkbox) {
        $if_settings[] = 'workflow_' . $checkbox;
      }
      $settings = array_merge($settings, $if_settings);
  }
}