You are here

function ais_admin_settings in Adaptive Image Styles (ais) 7

Generates the AIS administration form

1 string reference to 'ais_admin_settings'
ais_menu in ./ais.module
Implements hook_menu().

File

./ais.admin.inc, line 10
Administrative forms for Adaptive Image Styles.

Code

function ais_admin_settings($form, &$form_state) {
  $form = array();
  $aischoose = variable_get('ais_adaptive_styles_method', 'both-max');
  $form['aischoose'] = array(
    '#type' => 'select',
    '#title' => t('Threshold Determination Method'),
    '#options' => array(
      'both-max' => t('Maximum of Width and Height'),
      'both-min' => t('Minimum of Width and Height'),
      'width' => t('Width'),
      'height' => t('Height'),
    ),
    '#default_value' => $aischoose,
    '#description' => t("Method that the browser's size is decided.<br /><ul>\n<li>The maximum of the browser width and height will select a better resolution image and work well for both portrait and landscape images.</li>\n<li>The minimum of the browser width and height will select a smaller image and and work well for both portrait and landscape images.</li>\n<li>By width of the browser will work best for displaying mostly landscape images.</li>\n<li>By height of the browser will work best for displaying mostly portrait images.</li></ul>\n    "),
  );
  $form['ais'] = array(
    '#title' => t("Adaptive Image Styles"),
    '#type' => 'vertical_tabs',
  );
  $form['ais']['#attached']['js'] = array(
    drupal_get_path('module', 'ais') . '/assets/js/ais.admin.js',
  );
  $ais = variable_get("ais_adaptive_styles", array());
  $styles = image_styles();
  foreach ($styles as $is) {
    if ($is['name'] == 'adaptive') {
      continue;
    }
    $width = 0;
    foreach ($is['effects'] as $effect) {
      if (isset($effect['data']['width'])) {
        $width = $effect['data']['width'];
        break;
      }
    }
    $name = $is['name'];
    $nameset = $name . "_set";
    $namesize = $name . "_size";
    $form['ais'][$nameset] = array(
      '#title' => $is['name'],
      '#type' => 'fieldset',
      '#attributes' => array(
        'class' => array(
          'ais-settings-form',
        ),
      ),
    );
    $form['ais'][$nameset][$name]['#title'] = t("Selected");
    $form['ais'][$nameset][$name]['#type'] = 'checkbox';
    $form['ais'][$nameset][$name]['#default_value'] = isset($form_state['values'][$name]) ? $form_state['values'][$name] : _ais_is_used($name, $ais);
    $size = _ais_get_size($name, $ais);
    if (!isset($size) or $size == "") {
      $size = $width;
    }
    $form['ais'][$nameset][$namesize] = array();
    $form['ais'][$nameset][$namesize]['#type'] = 'textfield';
    $form['ais'][$nameset][$namesize]['#description'] = t('Threshold');
    $form['ais'][$nameset][$namesize]['#states'] = array(
      'invisible' => array(
        'input[name="' . $name . '"]' => array(
          'checked' => FALSE,
        ),
      ),
    );
    $form['ais'][$nameset][$namesize]['#default_value'] = isset($form_state['values'][$namesize]) ? $form_state['values'][$namesize] : $size;
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  $form['#validate'][] = 'ais_admin_settings_validate';
  $form['#submit'][] = 'ais_admin_settings_submit';
  return $form;
}