You are here

iss.admin.inc in Image Style Selector 7.2

File

iss.admin.inc
View source
<?php

/**
 * Form builder; Global settings configuration form.
 */
function iss_settings_form() {
  $form = array();
  $form['iss_apply_method'] = array(
    '#type' => 'radios',
    '#title' => t('Choose method of displaying changed image styles.'),
    '#options' => array(
      'default' => t('Default'),
      'preprocess_images' => t('@preprocess_images (experimental)', array(
        '@preprocess_images' => t('Preprocess images'),
      )),
    ),
    '#description' => t('There are a few different methods of displaying changed image styles. They differ by performance and capabilities. !default: Safer and faster, rely on altering formatters settings. Supports limited amount of formatters. !preprocess_images: Slower and experimental but should work also with views fields, and possibly in some other places.', array(
      '!default' => '<em>' . t('Default') . '</em>',
      '!preprocess_images' => '<em>' . t('Preprocess images') . '</em>',
    )),
    '#default_value' => variable_get('iss_apply_method', 'default'),
  );
  return system_settings_form($form);
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function iss_form_field_ui_field_edit_form_alter(&$form, $form_state) {
  if ($form['#field']['type'] != 'image') {
    return;
  }
  $settings_values =& $form['#instance']['settings'];
  $settings =& $form['instance']['settings'];
  $settings['iss'] = array(
    '#type' => 'fieldset',
    '#title' => t('Image Style Selector'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#weight' => 25,
    '#parents' => array(
      'instance',
      'settings',
      'iss',
    ),
  );
  $settings['iss']['iss_enabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable'),
    '#description' => t('Enable the Image Style Selector features.'),
    '#default_value' => !empty($settings_values['iss']['iss_enabled']),
  );
  $settings['iss']['config'] = array(
    '#type' => 'container',
    '#states' => array(
      'invisible' => array(
        'input[name="instance[settings][iss][iss_enabled]"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );
  $settings['iss']['config']['source_styles'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Source styles'),
    '#description' => t('Select all source styles, that will be available.'),
    '#options' => iss_image_styles('source'),
    '#default_value' => isset($settings_values['iss']['config']['source_styles']) ? $settings_values['iss']['config']['source_styles'] : array(),
    '#element_validate' => array(
      'iss_checkboxes_filter',
    ),
  );
  $settings['iss']['config']['target_styles'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Target styles'),
    '#description' => t('Select all target styles, that will be available.'),
    '#options' => iss_image_styles('target'),
    '#default_value' => isset($settings_values['iss']['config']['target_styles']) ? $settings_values['iss']['config']['target_styles'] : array(),
    '#element_validate' => array(
      'iss_checkboxes_filter',
    ),
  );
}

/**
 * Checkboxes element validation callback used to filter all unselected items
 * from the #value array.
 */
function iss_checkboxes_filter($element, &$form_state, $form) {
  if (isset($element['#value'])) {
    form_set_value($element, array_filter($element['#value']), $form_state);
  }
}

Functions

Namesort descending Description
iss_checkboxes_filter Checkboxes element validation callback used to filter all unselected items from the #value array.
iss_form_field_ui_field_edit_form_alter Implements hook_form_FORM_ID_alter().
iss_settings_form Form builder; Global settings configuration form.