You are here

function imagefield_extended_widget_settings in ImageField Extended 6.3

Implementation of hook_widget_settings().

File

./imagefield_extended.module, line 121
Insert additional fields into an ImageField data array.

Code

function imagefield_extended_widget_settings($op, $widget) {
  $extended_fields = _imagefield_extended_fields();
  $ife_textfields = $extended_fields['textfields'];
  $ife_workflow_checkboxes = $extended_fields['checkboxes'];
  switch ($op) {
    case 'form':
      $form = imagefield_widget_settings_form($widget);
      $weight = 12;
      foreach ($ife_textfields as $textfield => $title) {
        $title = check_plain($title);
        $form[$textfield . '_settings'] = array(
          '#type' => 'fieldset',
          '#title' => t('!field text settings', array(
            '!field' => drupal_ucfirst($title),
          )),
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
          '#weight' => $weight++,
        );
        $form[$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 images.', array(
            '!field' => $title,
          )),
        );
        $form[$textfield . '_settings']['custom_' . $textfield . '_required'] = array(
          '#type' => 'checkbox',
          '#title' => t('Required'),
          '#default_value' => empty($widget['custom_' . $textfield . '_required']) ? 0 : 1,
        );
        $form[$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'],
        );
        $form[$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,
          )),
        );
        $form[$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,
          )),
        );
      }
      $form['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);
        $form['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 images.', array(
            '!field' => $title,
          )),
        );
      }
      return $form;
    case 'validate':
      return imagefield_widget_settings_validate($widget);
    case 'save':
      $fields = array();
      foreach (array_keys($ife_textfields) as $textfield) {
        $fields[] = $textfield;
        $fields[] = $textfield . '_help';
        $fields[] = 'custom_' . $textfield;
        $fields[] = 'custom_' . $textfield . '_style';
        $fields[] = 'custom_' . $textfield . '_required';
      }
      foreach (array_keys($ife_workflow_checkboxes) as $checkbox) {
        $fields[] = 'workflow_' . $checkbox;
      }
      return array_merge(imagefield_widget_settings_save($widget), $fields);
  }
}