You are here

function manualcrop_field_widget_settings_form_alter in Manual Crop 7

Alters the existing field widget settings form elements.

Parameters

$form: Instance form elements array.

1 call to manualcrop_field_widget_settings_form_alter()
manualcrop_form_field_ui_field_edit_form_alter in ./manualcrop.admin.inc
Implements hook_form_FORM_ID_alter().

File

./manualcrop.admin.inc, line 763
Admin functionality for the Manual Crop module.

Code

function manualcrop_field_widget_settings_form_alter(&$form, $settings) {
  if ($form['widget']['type']['#value'] == 'image_image' && isset($settings['preview_image_style'])) {

    // Disable the image field preview if the thumblist option is enabled.
    $form['widget']['settings']['preview_image_style']['#states'] = array(
      'disabled' => array(
        'input[name="instance[widget][settings][manualcrop_enable]"]' => array(
          'checked' => TRUE,
        ),
        'input[name="instance[widget][settings][manualcrop_thumblist]"]' => array(
          'checked' => TRUE,
        ),
      ),
    );
  }
  if (module_exists('insert') && isset($form['settings']['insert'])) {

    // Get the reference to the insert fieldset.
    $insert =& $form['settings']['insert'];

    // Make sure the insert checkbox stays on top.
    $insert['insert']['#weight'] = -2;

    // Add an option to exclude image styles without a Manual Crop effect.
    $insert['manualcrop_filter_insert'] = array(
      '#type' => 'checkbox',
      '#title' => t('Only Manual Crop styles'),
      '#description' => t('Enable this option to filter out all image styles without a Manual Crop effect.'),
      '#default_value' => !empty($settings['manualcrop_filter_insert']),
      '#weight' => -1,
      '#states' => array(
        'disabled' => array(
          'input[name="instance[widget][settings][manualcrop_enable]"]' => array(
            'checked' => FALSE,
          ),
        ),
      ),
    );

    // If checked, remove all non-Manual Crop styles.
    if (!empty($settings['manualcrop_enable']) && !empty($settings['manualcrop_filter_insert'])) {
      $styles = array_merge(array(
        'image' => 0,
      ), manualcrop_insert_styles());
      $insert['insert_styles']['#options'] = array_intersect_key($insert['insert_styles']['#options'], $styles);
      $insert['insert_default']['#options'] = array_intersect_key($insert['insert_default']['#options'], $styles);
    }
  }
}