You are here

public function RateDefaultWidget::__toString in Rate 7.2

Generate HTML code for widget.

Return value

string

Overrides RateWidget::__toString

File

classes/default.inc, line 151

Class

RateDefaultWidget

Code

public function __toString() {
  $output = '';

  // Add generic javascript.
  drupal_add_js(array(
    'rate' => array(
      'basePath' => url('rate/vote/js'),
      'destination' => drupal_get_destination(),
    ),
  ), array(
    'type' => 'setting',
  ));
  drupal_add_js(drupal_get_path('module', 'rate') . '/rate.js');

  // Add widget specific javascript and CSS.
  if ($this->js_file) {
    drupal_add_js($this->js_file);
  }
  if ($this->css_file) {
    drupal_add_css($this->css_file);
  }
  foreach ($this->layout as $element) {
    if (isset($this->elements[$element->type])) {
      $output .= $element->prefix;
      $output .= (string) $this->elements[$element->type];
      $output .= $element->suffix;
    }
  }
  $classes = array(
    'rate-widget',
    "rate-widget-{$this->type}",
  );
  $classes[] = $this->displayed == RATE_AVERAGE ? 'average-rating' : 'user-rating';
  $classes[] = $this->voted ? 'voted' : 'not-voted';
  if ($this->mode == 'format_full_disabled' || $this->mode == 'format_compact_disabled' || $this->mode == 'format_closed') {
    $classes[] = 'disabled';
  }
  else {
    $classes[] = 'enabled';
  }
  if ($this->mode == 'format_closed') {
    $classes[] = 'closed';
  }
  if ($this->mode == 'format_compact' || $this->mode == 'format_compact_disabled') {
    $classes[] = 'compact';
  }
  $attributes = array(
    'class' => $classes,
    'data-entity-type' => $this->entity_type,
    'data-entity-id' => $this->entity_id,
    'data-field' => $this->field_name,
    'data-mode' => $this->mode,
    'data-highlight-mouseover' => $this->highlight_mouseover,
    'data-desc-mouseover' => $this->desc_mouseover,
  );
  $output = "<div" . drupal_attributes($attributes) . ">{$output}</div>";
  return $output;
}