You are here

function smileys_form_alter in Smileys 6

Same name and namespace in other branches
  1. 5 smileys.module \smileys_form_alter()

Implementation of hook_form_alter().

File

./smileys.module, line 67

Code

function smileys_form_alter(&$form, $form_state, $form_id) {
  if ($form_id != 'comment_form' && !isset($form['#node'])) {
    return;
  }
  if ($form_id == 'comment_form') {
    $node_type = db_result(db_query('SELECT type FROM {node} WHERE nid=%d', $form['nid']['#value']));
  }
  else {
    if (!empty($form['type']['#value'])) {
      $node_type = $form['type']['#value'];
    }
  }
  if (in_array($node_type, variable_get('smileys_node_types_content', array()), TRUE)) {
    if (user_access('use smiley select box') && (isset($form['type']) && $form['type']['#value'] . '_node_form' == $form_id && variable_get('smileys_enable_for_nodes', 0) && isset($form['body_field']) || 'comment_form' == $form_id && variable_get('smileys_enable_for_comments', 0))) {
      $output = '';
      if (array_key_exists('body_field', $form)) {
        $key = 'body_field';
      }
      elseif (array_key_exists('comment_filter', $form)) {
        $key = 'comment_filter';
      }
      else {
        $key = 'smileys_wrapper';
      }
      $collapsed = variable_get('smileys_select_box_expanded', TRUE) ? FALSE : TRUE;
      $form[$key]['smileys'] = array(
        '#type' => 'fieldset',
        '#title' => t('Smileys'),
        '#collapsible' => TRUE,
        '#collapsed' => $collapsed,
        '#weight' => 0,
        '#prefix' => '<div class="smileys-box">',
        '#suffix' => '</div>',
      );
      $form[$key]['smileys']['smileys_box'] = array(
        '#type' => 'markup',
        '#value' => theme('smileys_select_table', TRUE),
      );
      _smileys_add_files();
    }
  }
  return $form;
}