You are here

function imagepicker_form_alter in Image Picker 5.2

Same name and namespace in other branches
  1. 5 imagepicker.module \imagepicker_form_alter()
  2. 6.2 imagepicker.module \imagepicker_form_alter()
  3. 7 imagepicker.module \imagepicker_form_alter()

Implementation of hook_form_alter().

File

./imagepicker.module, line 197
Enables permitted roles to upload images for insertion into configured nodes.

Code

function imagepicker_form_alter($form_id, &$form) {
  $node = $form['#node'];
  $node_types = node_get_types('names');
  $node_type = in_array($node->type, variable_get('imagepicker_node_types_enabled', $node_types), TRUE);

  // comment
  $comment = FALSE;
  $weight = 1;
  if (module_exists('comment') && variable_get('imagepicker_comment_enabled', 0) && preg_match('/comment_form$/i', $form_id)) {
    $comment = TRUE;
    $weight = 1;
  }

  // blocks
  $block = FALSE;
  if (preg_match('/block_box_form$/i', $form_id) && variable_get('imagepicker_blocks_enabled', 0)) {
    $block = TRUE;
    $weight = 1;
  }
  if (user_access('use imagepicker')) {
    if ($node_type && preg_match('/node_form$/i', $form_id) || $comment) {
      $form['body_filter']['file_upload'] = array(
        '#type' => 'fieldset',
        '#title' => t('Image picker'),
        '#collapsible' => 1,
        '#collapsed' => variable_get('imagepicker_advanced_collapsed', 0),
        '#weight' => $weight,
        '#validate' => array(),
        '#theme' => 'imagepicker_iframe',
        1 => array(),
      );
      $form['body_filter']['#prefix'] = '<a name="body_hash"></a>' . $form['body_filter']['#prefix'];
    }
    elseif ($block) {
      $form['block_settings']['file_upload'] = array(
        '#type' => 'fieldset',
        '#title' => t('Image picker'),
        '#collapsible' => 1,
        '#collapsed' => variable_get('imagepicker_advanced_collapsed', 0),
        '#weight' => $weight,
        '#validate' => array(),
        '#theme' => 'imagepicker_iframe',
        1 => array(),
      );
      $form['block_settings']['#prefix'] = '<a name="body_hash"></a>' . $form['block_settings']['#prefix'];
    }
  }
}