You are here

function photos_form_alter in Album Photos 7.3

Same name and namespace in other branches
  1. 8.5 photos.module \photos_form_alter()
  2. 8.4 photos.module \photos_form_alter()
  3. 6.2 photos.module \photos_form_alter()
  4. 6.0.x photos.module \photos_form_alter()

Implements hook_form_alter().

File

./photos.module, line 949
Implementation of photos.module.

Code

function photos_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'node_type_form' && isset($form['#node_type']) && arg(3) != 'photos') {
    $form['photos'] = array(
      '#type' => 'fieldset',
      '#title' => t('Sub-Album settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#group' => 'additional_settings',
    );
    $form['photos']['photos_node'] = array(
      '#type' => 'radios',
      '#title' => t('Sub-Album'),
      '#default_value' => variable_get('photos_node_' . $form['#node_type']->type, 0),
      '#options' => array(
        t('Disabled'),
        t('Enabled'),
      ),
      '#description' => t('Node will become a sub-album, you can add images from other albums to this node.'),
    );
    $form['photos']['photos_share'] = array(
      '#type' => 'radios',
      '#title' => t('Reference'),
      '#default_value' => variable_get('photos_share_' . $form['#node_type']->type, 0),
      '#options' => array(
        t('Disabled'),
        t('Enabled'),
      ),
      '#description' => t('Displays a shortcut to the image share code that can be copied and pasted.'),
    );
  }
  if ($form_id == 'comment_node_photos_form' && variable_get('photos_comment', 0) || $form_id == 'comment_form' && variable_get('photos_comment', 0)) {
    if (isset($form_state['input']['photos_fid'])) {
      $fid = $form_state['input']['photos_fid'];
    }
    elseif (isset($form_state['input']['fid'])) {
      $fid = $form_state['input']['fid'];
    }
    elseif (arg(0) == 'photos' && is_numeric(arg(2))) {
      $fid = arg(2);
    }
    elseif (arg(1) == 'reply' && is_numeric(arg(3))) {
      $fid = db_query('SELECT fid FROM {photos_comment} WHERE cid = :cid', array(
        ':cid' => arg(3),
      ))
        ->fetchField();
    }
    if (isset($fid)) {
      $form['fid'] = array(
        '#type' => 'hidden',
        '#value' => $fid,
      );
      $form['comment']['photos_fid'] = array(
        '#type' => 'hidden',
        '#value' => $fid,
      );
    }
    $form['#submit'][] = 'photos_comment_form_submit';
  }
  if (isset($form['type']) && isset($form['#node']) && user_access('view photo')) {
    $node = $form['#node'];
    if (variable_get('photos_share_' . $node->type, 0)) {
      $form['photos_share'] = array(
        '#title' => t('Insert image'),
        '#weight' => 0,
        '#type' => 'fieldset',
        '#collapsible' => TRUE,
      );
      $form['photos_share']['share']['#markup'] = '<div id="potos-colorbox">' . l(t('Insert an existing image'), 'photos/share', array(
        'query' => array(
          'iframe' => 'true',
          'height' => 650,
          'width' => 850,
        ),
        'attributes' => array(
          'title' => t('Choose an image from my albums to insert into the node'),
          'class' => array(
            'colorbox-load',
          ),
        ),
      )) . ' (' . l(t('Open a new window'), 'photos/share', array(
        'attributes' => array(
          'title' => t('Choose an image from my albums to insert into the node'),
          'target' => '_blank',
        ),
      )) . ')</div>';
    }
  }
  if ($form_id == 'photos_node_form') {
    $form['actions']['submit']['#submit'][] = 'photos_form_redirect';
  }
}