You are here

function reviews_add_review in Reviews 7

Form builder for add review page.

1 string reference to 'reviews_add_review'
reviews_menu in ./reviews.module
Implements hook_menu().

File

includes/reviews.pages.inc, line 61
This file contain all function necessary for displaying and leaving reviews.

Code

function reviews_add_review($form, &$form_state, $nid) {
  global $user;
  if (reviews_check_user_review($nid, $user->uid)) {
    $form['intro'] = array(
      '#type' => 'item',
      '#markup' => t('You have already left a review for this page!'),
    );
  }
  else {
    $form = array();
    $node = node_load($nid);
    $title = $node->title;
    $form['intro'] = array(
      '#type' => 'item',
      '#markup' => t('Complete the form below to leave a review of <em>!title</em>', array(
        '!title' => check_plain($title),
      )),
    );
    $form['nid'] = array(
      '#type' => 'hidden',
      '#value' => $nid,
    );
    $form['uid'] = array(
      '#type' => 'hidden',
      '#value' => $user->uid,
    );
    $form['review'] = array(
      '#type' => 'text_format',
      '#title' => t('Your review'),
      '#rows' => 10,
      '#required' => TRUE,
    );
    if (variable_get('reviews_use_rating') and module_exists('fivestar')) {
      $widgets = module_invoke_all('fivestar_widgets');
      $widgets = $widgets + array(
        'default' => t('Default'),
      );
      $widget = array(
        'name' => $widgets[variable_get('reviews_rating_star_widget')],
        'css' => 'active',
      );
      $settings = array(
        'stars' => variable_get('reviews_rating_star_count', 5),
        'allow_clear' => FALSE,
        'style' => 'user',
        'text' => 'none',
        'widget' => $widget,
      );
      $values = array(
        'user' => 0,
        'average' => 0,
        'count' => 0,
      );
      $form['rating'] = array(
        '#type' => 'fivestar',
        '#title' => t('Your rating'),
        '#stars' => variable_get('reviews_rating_star_count', 5),
        '#allow_clear' => FALSE,
        '#settings' => $settings,
        '#values' => $values,
        '#required' => TRUE,
      );
    }
    $form['actions'] = array(
      '#type' => 'actions',
    );
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Submit Review'),
    );
  }
  return $form;
}