function image_style_form

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

Parameters

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

$style: An image style array.

See also

image_style_form_submit()

Related topics

1 string reference to 'image_style_form'
image_menu in drupal/core/modules/image/image.module
Implements hook_menu().

File

drupal/core/modules/image/image.admin.inc, line 36
Administration pages for image settings.

Code

function image_style_form($form, &$form_state, $style) {
  $title = t('Edit style %name', array(
    '%name' => $style
      ->label(),
  ));
  drupal_set_title($title, PASS_THROUGH);
  $form_state['image_style'] = $style;
  $form['#tree'] = TRUE;
  $form['#attached']['css'][drupal_get_path('module', 'image') . '/css/image.admin.css'] = array();

  // Show the thumbnail preview.
  $form['preview'] = array(
    '#type' => 'item',
    '#title' => t('Preview'),
    '#markup' => theme('image_style_preview', array(
      'style' => $style,
    )),
  );
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => t('Administrative label'),
    '#default_value' => $style
      ->label(),
    '#required' => TRUE,
  );
  $form['name'] = array(
    '#type' => 'machine_name',
    '#default_value' => $style
      ->id(),
    '#machine_name' => array(
      'exists' => 'image_style_load',
    ),
    '#required' => TRUE,
  );

  // Build the list of existing image effects for this image style.
  $form['effects'] = array(
    '#theme' => 'image_style_effects',
  );
  if (!empty($style->effects)) {
    foreach ($style->effects as $key => $effect) {
      $form['effects'][$key]['#weight'] = isset($form_state['input']['effects']) ? $form_state['input']['effects'][$key]['weight'] : NULL;
      $form['effects'][$key]['label'] = array(
        '#markup' => check_plain($effect['label']),
      );
      $form['effects'][$key]['summary'] = array(
        '#markup' => isset($effect['summary theme']) ? theme($effect['summary theme'], array(
          'data' => $effect['data'],
        )) : '',
      );
      $form['effects'][$key]['weight'] = array(
        '#type' => 'weight',
        '#title' => t('Weight for @title', array(
          '@title' => $effect['label'],
        )),
        '#title_display' => 'invisible',
        '#default_value' => $effect['weight'],
      );
      $links = array();
      if (isset($effect['form callback'])) {
        $links['edit'] = array(
          'title' => t('edit'),
          'href' => 'admin/config/media/image-styles/manage/' . $style
            ->id() . '/effects/' . $key,
        );
      }
      $links['delete'] = array(
        'title' => t('delete'),
        'href' => 'admin/config/media/image-styles/manage/' . $style
          ->id() . '/effects/' . $key . '/delete',
      );
      $form['effects'][$key]['operations'] = array(
        '#type' => 'operations',
        '#links' => $links,
      );
      $form['effects'][$key]['configure'] = array(
        '#type' => 'link',
        '#title' => t('edit'),
        '#href' => 'admin/config/media/image-styles/manage/' . $style
          ->id() . '/effects/' . $key,
        '#access' => isset($effect['form callback']),
      );
      $form['effects'][$key]['remove'] = array(
        '#type' => 'link',
        '#title' => t('delete'),
        '#href' => 'admin/config/media/image-styles/manage/' . $style
          ->id() . '/effects/' . $key . '/delete',
      );
    }
  }

  // Build the new image effect addition form and add it to the effect list.
  $new_effect_options = array();
  foreach (image_effect_definitions() as $effect => $definition) {
    $new_effect_options[$effect] = $definition['label'];
  }
  $form['effects']['new'] = array(
    '#tree' => FALSE,
    '#weight' => isset($form_state['input']['weight']) ? $form_state['input']['weight'] : NULL,
  );
  $form['effects']['new']['new'] = array(
    '#type' => 'select',
    '#title' => t('Effect'),
    '#title_display' => 'invisible',
    '#options' => $new_effect_options,
    '#empty_option' => t('Select a new effect'),
  );
  $form['effects']['new']['weight'] = array(
    '#type' => 'weight',
    '#title' => t('Weight for new effect'),
    '#title_display' => 'invisible',
    '#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['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update style'),
  );
  return $form;
}