image_style_form

Versions
mediamosa-21
image_style_form($form, &$form_state, $style)

Form builder; Edit an image style name and effects order.

See also

image_style_form_submit()

@see image_style_name_validate()

Parameters

$form_state An associative array containing the current state of the form.

$style An image style array.

Related topics

Code

modules/image/image.admin.inc, line 37

<?php
function image_style_form($form, &$form_state, $style) {
  $title = t('Edit %name style', array('%name' => $style['name']));
  drupal_set_title($title, PASS_THROUGH);

  // Adjust this form for styles that must be overridden to edit.
  $editable = (bool) ($style['storage'] & IMAGE_STORAGE_EDITABLE);

  if (!$editable && empty($form_state['input'])) {
    drupal_set_message(t('This image style is currently being provided by a module. Click the "Override defaults" button to change its settings.'), 'warning');
  }

  $form_state['image_style'] = $style;
  $form['#tree'] = TRUE;
  $form['#attached']['css'][drupal_get_path('module', 'image') . '/image.admin.css'] = array('preprocess' => FALSE);

  // Show the thumbnail preview.
  $form['preview'] = array(
    '#type' => 'item',
    '#title' => t('Preview'),
    '#markup' => theme('image_style_preview', array('style' => $style)),
  );

  // Allow the name of the style to be changed, unless this style is
  // provided by a module's hook_default_image_styles().
  if ($style['storage'] & IMAGE_STORAGE_MODULE) {
    $form['name'] = array(
      '#type' => 'item',
      '#title' => t('Image style name'),
      '#markup' => $style['name'],
      '#description' => t('This image style is being provided by %module module and may not be renamed.', array('%module' => $style['module'])),
    );
  }
  else {
    $form['name'] = array(
      '#type' => 'textfield',
      '#size' => '64',
      '#title' => t('Image style name'),
      '#default_value' => $style['name'],
      '#description' => t('The name is used in URLs for generated images. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'),
      '#element_validate' => array('image_style_name_validate'),
      '#required' => TRUE,
    );
  }

  // Build the list of existing image effects for this image style.
  $form['effects'] = array(
    '#theme' => 'image_style_effects',
  );
  foreach ($style['effects'] as $ieid => $effect) {
    $form['effects'][$ieid]['#weight'] = isset($form_state['input']['effects']) ? $form_state['input']['effects'][$ieid]['weight'] : NULL;
    $form['effects'][$ieid]['label'] = array(
      '#markup' => $effect['label'],
    );
    $form['effects'][$ieid]['summary'] = array(
      '#markup' => isset($effect['summary theme']) ? theme($effect['summary theme'], array('data' => $effect['data'])) : '',
    );
    $form['effects'][$ieid]['weight'] = array(
      '#type' => 'weight',
      '#default_value' => $effect['weight'],
      '#access' => $editable,
    );
    $form['effects'][$ieid]['configure'] = array(
      '#type' => 'link',
      '#title' => t('edit'),
      '#href' => 'admin/config/media/image-styles/edit/' . $style['name'] . '/effects/' . $effect['ieid'],
      '#access' => $editable && isset($effect['form callback']),
    );
    $form['effects'][$ieid]['remove'] = array(
      '#type' => 'link',
      '#title' => t('delete'),
      '#href' => 'admin/config/media/image-styles/edit/' . $style['name'] . '/effects/' . $effect['ieid'] . '/delete',
      '#access' => $editable,
    );
  }

  // Build the new image effect addition form and add it to the effect list.
  $new_effect_options = array('' => t('Select a new effect'));
  foreach (image_effect_definitions() as $effect => $definition) {
    $new_effect_options[$effect] = check_plain($definition['label']);
  }
  $form['effects']['new'] = array(
    '#tree' => FALSE,
    '#weight' => isset($form_state['input']['weight']) ? $form_state['input']['weight'] : NULL,
    '#access' => $editable,
  );
  $form['effects']['new']['new'] = array(
    '#type' => 'select',
    '#options' => $new_effect_options,
  );
  $form['effects']['new']['weight'] = array(
    '#type' => 'weight',
    '#default_value' => count($form['effects']) - 1,
  );
  $form['effects']['new']['add'] = array(
    '#type' => 'submit',
    '#value' => t('Add'),
    '#validate' => array('image_style_form_add_validate'),
    '#submit' => array('image_style_form_submit', 'image_style_form_add_submit'),
  );

  // Show the Override or Submit button for this style.
  $form['override'] = array(
    '#type' => 'submit',
    '#value' => t('Override defaults'),
    '#validate' => array(),
    '#submit' => array('image_style_form_override_submit'),
    '#access' => !$editable,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update style'),
    '#access' => $editable,
  );

  return $form;
}
?>