You are here

function image_replace_form_field_ui_field_edit_form_alter in Image Replace 7

Implements hook_form_FORM_ID_alter().

Add per image-field instance settings for image style replacement.

File

./image_replace.module, line 69
Provides an image style effect replacing the whole image with another one.

Code

function image_replace_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
  if ($form['#field']['type'] == 'image') {
    $instance = $form['#instance'];
    $form['instance']['settings']['image_replace'] = array(
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#title' => t('Image replace'),
      '#description' => t('Use another image when rendered with certain image styles.'),
      '#weight' => 99,
      '#tree' => TRUE,
      '#element_validate' => array(
        'image_replace_form_field_ui_field_edit_form_element_validate',
      ),
    );
    $image_field_options = array();
    foreach (_image_replace_image_instances($instance['entity_type'], $instance['bundle']) as $field_name => $info) {
      $image_field_options[$field_name] = check_plain($info['label']);
    }
    unset($image_field_options[$form['#field']['field_name']]);
    foreach (_image_replace_style_options() as $image_style => $label) {
      $default_value = _image_replace_instance_setting($instance, 'source_field', $image_style);
      $form['instance']['settings']['image_replace'][$image_style]['source_field'] = array(
        '#type' => 'select',
        '#title' => $label,
        '#description' => t('The image field to use as a source when rendered with the %style image style.', array(
          '%style' => $label,
        )),
        '#options' => $image_field_options,
        '#default_value' => $default_value,
        '#empty_value' => FALSE,
      );
      if ($default_value) {
        $form['instance']['settings']['image_replace']['#collapsed'] = FALSE;
      }
    }
  }
}