You are here

function imageapi_optimize_services_internal_form in Image Optimize (or ImageAPI Optimize) 7

Internal ImageAPI Optimize form callback.

File

services/internal.inc, line 21
Internal ImageAPI Optimize service.

Code

function imageapi_optimize_services_internal_form($info) {
  $form = array();
  $form['types'] = array(
    '#type' => 'vertical_tabs',
  );
  foreach ($info['binaries'] as $name => $binary) {
    $settings = variable_get('imageapi_optimize_' . $name, array());
    if (!isset($form['types'][$binary['type']])) {
      $form['types'][$binary['type']] = array(
        '#title' => t('@type Settings', array(
          '@type' => drupal_strtoupper($binary['type']),
        )),
        '#type' => 'fieldset',
        '#theme' => 'imageapi_optimize_services_internal_form',
      );
    }
    $form['types'][$binary['type']]['imageapi_optimize_' . $name] = array(
      '#type' => 'container',
      '#tree' => TRUE,
    );
    $form['types'][$binary['type']]['imageapi_optimize_' . $name]['status'] = array(
      '#title' => t('Enabled'),
      '#type' => 'checkbox',
      '#default_value' => isset($settings['status']) ? $settings['status'] : FALSE,
      '#title_display' => 'invisible',
    );
    $form['types'][$binary['type']]['imageapi_optimize_' . $name]['title'] = array(
      '#markup' => t('@title (@name)', array(
        '@title' => $binary['title'],
        '@name' => $name,
      )),
    );
    if (isset($binary['url'])) {
      $form['types'][$binary['type']]['imageapi_optimize_' . $name]['title']['#markup'] = l($form['types'][$binary['type']]['imageapi_optimize_' . $name]['title']['#markup'], $binary['url']);
    }
    $form['types'][$binary['type']]['imageapi_optimize_' . $name]['path'] = array(
      '#type' => 'textfield',
      '#title' => t('Path to @name', array(
        '@name' => $name,
      )),
      '#default_value' => isset($settings['path']) ? $settings['path'] : '',
      '#element_validate' => array(
        'imageapi_optimize_validate_path',
      ),
      '#title_display' => 'invisible',
    );
    if (isset($binary['description'])) {
      $form['types'][$binary['type']]['imageapi_optimize_' . $name]['path']['#description'] = $binary['description'];
    }
    $op = '';
    if (!empty($binary['settings'])) {
      $op = l(t('Advanced settings'), 'admin/config/media/image-toolkit/imageapi_optimize/' . $name);
      $advanced_settings = isset($settings['settings']) ? $settings['settings'] : $binary['settings'];
      $form['types'][$binary['type']]['imageapi_optimize_' . $name]['settings'] = array(
        '#type' => 'value',
        '#value' => $advanced_settings,
      );
    }
    $form['types'][$binary['type']]['imageapi_optimize_' . $name]['op'] = array(
      '#markup' => $op,
    );
    $form['types'][$binary['type']]['imageapi_optimize_' . $name]['weight'] = array(
      '#title' => t('Weight'),
      '#type' => 'weight',
      '#default_value' => $binary['weight'],
      '#title_display' => 'invisible',
    );
  }
  return $form;
}