Index: includes/fivestar.theme.inc
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- includes/fivestar.theme.inc	(revision ee888670ec1276ecf313da7caa38800f62190c32)
+++ includes/fivestar.theme.inc	(revision )
@@ -215,11 +215,6 @@
   $stars = $variables['stars'];
   $tag = $variables['tag'];
   $widget = $variables['widget'];
-  if ($widget['name'] != 'default') {
-    $path = drupal_get_path('module', 'fivestar');
-    drupal_add_css($path . '/css/fivestar.css');
-    drupal_add_css($widget['css']);
-  }
 
   $output = '<div class="fivestar-' . $widget['name'] . '">';
   $output .= '<div class="fivestar-widget-static fivestar-widget-static-' . $tag . ' fivestar-widget-static-' . $stars . ' clearfix">';
@@ -339,23 +334,24 @@
  * Display a static fivestar value as stars with a title and description.
  */
 function theme_fivestar_static_element($variables) {
-  $output = '';
-  if (isset($variables['is_form']) && !$variables['is_form']) {
-    $output .= '<div class="fivestar-static-item">';
+  if (isset($variables['#is_form']) && !$variables['#is_form']) {
+    $prefix = '<div class="fivestar-static-item">';
   }
   else {
-    $output .= '<div class="fivestar-static-form-item">';
+    $prefix = '<div class="fivestar-static-form-item">';
   }
-  $element = [
+  $result = [
     '#type' => 'item',
     '#title' => $variables['title'],
     '#description' => $variables['description'],
-    '#children' => $variables['star_display'],
+    '#markup' => \Drupal::service('renderer')->render($variables['star_display']),
+    '#theme_wrappers' => array('form_element'),
+    '#prefix' => $prefix,
+    '#suffix' => '</div>',
   ];
 
-  $output .= theme('form_element', ['element' => $element]);
-  $output .= '</div>';
-  return $output;
+
+  return \Drupal::service('renderer')->render($result);
 }
 
 /**
@@ -387,6 +383,7 @@
     '#allow_clear' => $element['#settings']['allow_clear'],
     '#allow_revote' => $element['#settings']['allow_revote'],
     '#allow_ownvote' => $element['#settings']['allow_ownvote'],
+    '#allow_edit' => $element['#settings']['allow_edit'],
     '#widget' => $element['#widget'],
     '#default_value' => $element['#default_value'],
   ];
Index: fivestar.permissions.yml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- fivestar.permissions.yml	(revision )
+++ fivestar.permissions.yml	(revision )
@@ -0,0 +1,2 @@
+rate content:
+  title: 'Rate content'
Index: src/Element/Fivestar.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/Element/Fivestar.php	(revision ee888670ec1276ecf313da7caa38800f62190c32)
+++ src/Element/Fivestar.php	(revision )
@@ -168,16 +168,16 @@
         $static_average = [
           '#type' => 'fivestar_static',
           '#rating' => $values['average'],
-          '#stars' => $settings['stars'],
-          '#tag' => $settings['tag'],
-          '#widget' => $settings['widget'],
+          '#stars' => $element['#stars'],
+          '#tag' => !empty($settings['#tag']) ? $settings['#tag'] : '',
+          '#widget' => $element['#widget'],
         ];
         if ($settings['text'] != 'none') {
           $static_description = [
             '#type' => 'fivestar_summary',
             '#average_rating' => $settings['text'] == 'user' ? NULL : (isset($values['average']) ? $values['average'] : 0),
             '#votes' => isset($values['count']) ? $values['count'] : 0,
-            '#stars' => $settings['stars'],
+            '#stars' => $element['#stars'],
           ];
         }
         else {
@@ -214,22 +214,22 @@
 
     if (empty($element['#input'])) {
       $static_stars = [
-        '#type' => 'fivestar_static',
+        '#theme' => 'fivestar_static',
         '#rating' => $element['vote']['#default_value'],
-        '#stars' => $settings['stars'],
-        '#tag' => $settings['tag'],
-        '#widget' => $settings['widget'],
+        '#tag' => !empty($settings['#tag']) ? $settings['#tag'] : '',
+        '#stars' => $element['#stars'],
+        '#widget' => $element['#widget'],
       ];
 
       $element_static = [
-        '#type' => 'fivestar_static_element',
+        '#theme' => 'fivestar_static_element',
         '#star_display' => $static_stars,
         '#title' => '',
         '#description' => $element['vote']['#description'],
       ];
       $element['vote'] = [
         '#type' => 'markup',
-        '#markup' => $element_static,
+        '#markup' =>  \Drupal::service('renderer')->render($element_static),
       ];
     }
 
@@ -249,6 +249,14 @@
   public static function isVoteAllowed($element) {
     $user = \Drupal::currentUser();
 
+    // Check allowed edit.
+    if (
+      (isset($element['#allow_edit']) && !$element['#allow_edit'])
+      || !$user->hasPermission('rate content')
+    ) {
+      return FALSE;
+    }
+
     // Check allowed to re-vote.
     $can_revote = FALSE;
     if ($element['#allow_revote']) {
Index: fivestar.module
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- fivestar.module	(revision ee888670ec1276ecf313da7caa38800f62190c32)
+++ fivestar.module	(revision )
@@ -73,7 +73,7 @@
     ],
     'fivestar_static_element' => [
       'function' => 'theme_fivestar_static_element',
-      'variables' => ['star_display' => NULL, 'title' => NULL, 'description' => NULL],
+      'variables' => ['star_display' => NULL, 'is_form' => NULL, 'title' => NULL, 'description' => NULL],
       'file' => 'includes/fivestar.theme.inc',
     ],
     'fivestar_summary' => [
Index: src/Plugin/Field/FieldFormatter/StarsFormatter.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/Plugin/Field/FieldFormatter/StarsFormatter.php	(revision ee888670ec1276ecf313da7caa38800f62190c32)
+++ src/Plugin/Field/FieldFormatter/StarsFormatter.php	(revision )
@@ -26,6 +26,7 @@
   public static function defaultSettings() {
     return [
       'fivestar_widget' => drupal_get_path('module', 'fivestar') . '/widgets/basic/basic.css',
+      'expose' => TRUE,
     ] + parent::defaultSettings();
   }
 
@@ -50,6 +51,12 @@
         'count' => 0,
       ];
 
+      // Determine if any set of stars to be displayed need to be
+      // displayed in a form. (That is, can the user click the stars
+      // to cast a vote?) If yes, hand off everything we know to the
+      // fivestar_custom_widget form, and let it take care of the rest.
+      $settings['allow_edit']  = $this->getSetting('expose') && $settings['rated_while'] == 'viewing';
+
       $elements[$delta] = [
         '#theme' => 'fivestar_output_widget',
         '#name' => $item->getName(),
@@ -76,6 +83,15 @@
       '#pre_render' => [[$this, 'previewsExpand']],
       '#attached' => ['library' => ['fivestar/fivestar.admin']],
     ];
+
+    if ($this->getFieldSetting('rated_while') == 'viewing') {
+      $elements['expose'] = [
+        '#type' => 'checkbox',
+        '#title' => t('Allow voting on the entity.'),
+        '#default_value' => $this->getSetting('expose') === NULL ? TRUE : $this->getSetting('expose'),
+        '#return_value' => 1,
+      ];
+    }
     return $elements;
   }
 
