You are here

function ml_image_attributes_form in Media Library 6

Form for modal dialog For updating media, use the contents of $form_state['update'] You can form_alter this safely to add any attributes you like They will show in the tag and will be available at the theme function automatically

1 string reference to 'ml_image_attributes_form'
ml_image_media_forms in ml_image/ml_image.module
Implementation of hook_media_forms()

File

ml_image/ml_image.module, line 344
Media Library Image module.

Code

function ml_image_attributes_form(&$form, &$form_state) {

  // Check for default value from content being updated
  if (isset($form_state['update'])) {
    $image = $form_state['update'];
  }
  else {
    $image = '';
  }

  // Put elements inside attributes array so we can separate
  // from form API elements such as form_id
  $form['attributes'] = array(
    '#tree' => TRUE,
  );
  $options = array_filter(variable_get('ml_image_imagecache_presets', array()));
  $options['none'] = t('Original Size');

  // Generates preview for image
  $option = isset($image['preset']) ? $image['preset'] : key($options);
  if ($option == 'none') {
    $imgtag = theme('image', $form_state['media_obj']->filepath);
  }
  else {
    $imgtag = theme('imagecache', $option, $form_state['media_obj']->filepath);
  }
  $form['preview'] = array(
    '#value' => '<div class="ml-image-edit preview">' . $imgtag . '</div>',
    '#weight' => -1,
  );

  // Size. Imagecache presets enabled
  $form['attributes']['preset'] = array(
    '#type' => 'select',
    '#title' => t('Image size'),
    '#description' => t('Predefined image size choice'),
    '#options' => $options,
    '#default_value' => isset($image['preset']) ? array(
      $image['preset'],
    ) : array(),
  );

  // Image alignment. This can be easily overriden by theme
  $form['attributes']['align'] = array(
    '#type' => 'select',
    '#title' => t('Image Alignment'),
    '#options' => array(
      'center' => t('Center'),
      'left' => t('Left'),
      'right' => t('Right'),
    ),
    '#default_value' => isset($image['align']) ? $image['align'] : 'center',
  );

  // Title of the block, primarily, but can be used for img title or alt
  $form['attributes']['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => isset($image['title']) ? $image['title'] : '',
  );

  // Legend. Small text to appear inside block
  $form['attributes']['label'] = array(
    '#type' => 'textfield',
    '#title' => t('Label'),
    '#default_value' => isset($image['label']) ? $image['label'] : '',
  );
  $form_state['no buttons'] = TRUE;
}