You are here

function theme_fivestar_preview in Fivestar 8

Same name and namespace in other branches
  1. 5 fivestar.module \theme_fivestar_preview()
  2. 6.2 includes/fivestar.admin.inc \theme_fivestar_preview()
  3. 6 fivestar.module \theme_fivestar_preview()
  4. 7.2 includes/fivestar.theme.inc \theme_fivestar_preview()
1 string reference to 'theme_fivestar_preview'
fivestar_theme in ./fivestar.module
Implements hook_theme().

File

includes/fivestar.theme.inc, line 73
Provides the theming functions for fivestar.

Code

function theme_fivestar_preview($variables) {
  extract($variables, EXTR_SKIP);
  $values = [
    'vote_average' => 50,
    'vote_user' => 80,
    'vote_count' => 20,
  ];
  $settings = [
    'stars' => $stars,
    'allow_clear' => $unvote,
    'allow_revote' => $revote,
    'allow_ownvote' => $ownvote,
    'style' => $style,
    'text' => $text,
    'title' => $title,
    'autosubmit' => FALSE,
    'vote_type' => 'vote',
  ];
  $form = drupal_get_form('fivestar_custom_widget', $values, $settings);
  $form = \Drupal::service('renderer')
    ->render($form);

  // This regex is sadly necessary because having duplicate form_tokens or
  // form_id elements can cause the content type form to choke. Forms inside of
  // forms is also frowned upon, so this removes the wrapping form tag as well.
  $form = str_replace([
    '<form',
    '</form>',
  ], [
    '<div',
    '</div>',
  ], $form);
  $form = preg_replace('/( method=".*?")|( action=".*?")|(<input.*?name="(form_token|form_id|destination|form_build_id)".*?\\/>)/', '', $form);
  return $form;
}