You are here

function imageblock_configure_form in Image Block 7

Same name and namespace in other branches
  1. 6 imageblock.module \imageblock_configure_form()
1 call to imageblock_configure_form()
imageblock_block_configure in ./imageblock.module
Implements hook_block_configure().

File

./imageblock.module, line 199
imageblock.module Primarily Drupal hooks.

Code

function imageblock_configure_form(&$form, $block = NULL) {
  $title = t('Image');
  $description = '';
  if (!empty($block['bid'])) {
    $file = imageblock_get_file($block['bid']);
    if (!empty($file->fid)) {
      $title = t('Change Image');
      $description = t('If new file is selected previous file will be deleted. This action cannot be undone.');
      $form['imageblock_prev'] = array(
        '#type' => 'item',
        '#title' => t('Image'),
        '#markup' => $file->filename,
        '#weight' => isset($form['body_field']['#weight']) ? $form['body_field']['#weight'] - 0.8 : 0,
      );
    }
  }

  // Do not require body as we can have an image as the body.
  $form['body_field']['body']['#required'] = FALSE;
  $data = !empty($block['data']) ? unserialize($block['data']) : array();
  $form['imageblock'] = array(
    '#type' => 'managed_file',
    '#title' => $title,
    '#description' => $description,
    '#size' => 40,
    '#weight' => isset($form['body_field']['#weight']) ? $form['body_field']['#weight'] - 0.7 : 0,
    '#upload_location' => 'public://',
  );
  $form['imageblock_alt'] = array(
    '#type' => 'textfield',
    '#title' => t('Alternate text'),
    '#description' => t('This text will be used by screen readers, search engines, or when the image cannot be loaded.'),
    '#size' => 40,
    '#default_value' => isset($data['imageblock_alt']) ? $data['imageblock_alt'] : '',
    '#weight' => isset($form['body_field']['#weight']) ? $form['body_field']['#weight'] - 0.5 : 0,
  );
  $form['imageblock_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#description' => t('The title is used as a tool tip when the user hovers the mouse over the image.'),
    '#size' => 40,
    '#default_value' => isset($data['imageblock_title']) ? $data['imageblock_title'] : '',
    '#weight' => isset($form['body_field']['#weight']) ? $form['body_field']['#weight'] - 0.4 : 0,
  );
  $form['imageblock_link'] = array(
    '#type' => 'textfield',
    '#title' => t('Link'),
    '#description' => t('Leave empty for no link.'),
    '#size' => 40,
    '#maxlength' => 2083,
    '#default_value' => isset($data['imageblock_link']) ? $data['imageblock_link'] : '',
    '#weight' => isset($form['body_field']['#weight']) ? $form['body_field']['#weight'] - 0.3 : 0,
  );
  $form['imageblock_link_target'] = array(
    '#type' => 'select',
    '#title' => t('Link target'),
    '#description' => t('Leave empty for no link.'),
    '#options' => array(
      '_blank' => '_blank',
      '_parent' => '_parent',
      '_self' => '_self',
      '_top' => '_top',
    ),
    '#default_value' => isset($data['imageblock_link_target']) ? $data['imageblock_link_target'] : '_self',
    '#weight' => isset($form['body_field']['#weight']) ? $form['body_field']['#weight'] - 0.2 : 0,
  );
  $form['imageblock_nofollow'] = array(
    '#type' => 'checkbox',
    '#title' => t('NoFollow option'),
    '#description' => t('Mark this item if you want add rel=nofollow to your link.</br> Links to an unendorsed document, like a paid link.(nofollow is ' . 'used by Google, to specify that the Google search spider should not follow that link)'),
    '#default_value' => isset($data['imageblock_nofollow']) ? $data['imageblock_nofollow'] : '0',
    '#weight' => isset($form['body_field']['#weight']) ? $form['body_field']['#weight'] - 0.1 : 0,
  );
  if (module_exists('image')) {
    $options = array();
    foreach (image_styles() as $key => $preset) {
      $options[$key] = $preset['name'];
    }
    if (!empty($options)) {
      $form['imageblock_imagecache'] = array(
        '#type' => 'select',
        '#title' => t('Image style'),
        '#options' => array(
          '' => t('<none>'),
        ) + $options,
        '#default_value' => isset($data['imageblock_imagecache']) ? $data['imageblock_imagecache'] : '',
        '#weight' => isset($form['body_field']['#weight']) ? $form['body_field']['#weight'] - 0.6 : 0,
      );
    }
  }
}