You are here

class FiveStarWidget in Votingapi Widgets 8

Assigns ownership of a node to a user.

Plugin annotation


@VotingApiWidget(
  id = "fivestar",
  label = @Translation("Fivestar rating"),
  values = {
   1 = @Translation("Poor"),
   2 = @Translation("Not so poor"),
   3 = @Translation("Average"),
   4 = @Translation("Good"),
   5 = @Translation("Very good"),
  },
)

Hierarchy

Expanded class hierarchy of FiveStarWidget

File

src/Plugin/votingapi_widget/FiveStarWidget.php, line 23

Namespace

Drupal\votingapi_widgets\Plugin\votingapi_widget
View source
class FiveStarWidget extends VotingApiWidgetBase {
  use StringTranslationTrait;

  /**
   * Vote form.
   */
  public function buildForm($entity_type, $entity_bundle, $entity_id, $vote_type, $field_name, $settings) {
    $form = $this
      ->getForm($entity_type, $entity_bundle, $entity_id, $vote_type, $field_name, $settings);
    $build = [
      'rating' => [
        '#theme' => 'container',
        '#attributes' => [
          'class' => [
            'votingapi-widgets',
            'fivestar',
            $settings['readonly'] === 1 ? 'read_only' : '',
          ],
        ],
        '#children' => [
          'form' => $form,
        ],
      ],
      '#attached' => [
        'library' => [
          'votingapi_widgets/fivestar',
        ],
      ],
    ];
    return $build;
  }

  /**
   * {@inheritdoc}
   */
  public function getInitialVotingElement(array &$form) {
    $form['value']['#prefix'] = '<div class="votingapi-widgets fivestar">';
    $form['value']['#attached'] = [
      'library' => [
        'votingapi_widgets/fivestar',
      ],
    ];
    $form['value']['#suffix'] = '</div>';
    $form['value']['#attributes'] = [
      'data-style' => 'default',
      'data-is-edit' => 1,
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getStyles() {
    return [
      'default' => $this
        ->t('Default'),
      'bars-horizontal' => $this
        ->t('Bars horizontal'),
      'css-stars' => $this
        ->t('Css stars'),
      'bars-movie' => $this
        ->t('Bars movie'),
      'bars-pill' => $this
        ->t('Bars pill'),
      'bars-square' => $this
        ->t('Bars square'),
      'fontawesome-stars-o' => $this
        ->t('Fontawesome stars-o'),
      'fontawesome-stars' => $this
        ->t('Fontawesome stars'),
      'bootstrap-stars' => $this
        ->t('Bootstrap stars'),
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FiveStarWidget::buildForm public function Vote form. Overrides VotingApiWidgetInterface::buildForm
FiveStarWidget::getInitialVotingElement public function Get initial element. Overrides VotingApiWidgetBase::getInitialVotingElement
FiveStarWidget::getStyles public function Get available styles. Overrides VotingApiWidgetInterface::getStyles
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
VotingApiWidgetBase::$account protected property The user account.
VotingApiWidgetBase::$configFactory protected property The config factory service.
VotingApiWidgetBase::$entityFormBuilder protected property The entity form builder service.
VotingApiWidgetBase::$entityTypeManager protected property The entity type manager service.
VotingApiWidgetBase::$requestStack protected property The request stack.
VotingApiWidgetBase::$votingapiResult protected property Vote result function manager service.
VotingApiWidgetBase::canVote public function Checks whether currentUser is allowed to vote.
VotingApiWidgetBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
VotingApiWidgetBase::getEntityForVoting public function Returns a Vote entity.
VotingApiWidgetBase::getForm public function Gets the widget form as configured for given parameters.
VotingApiWidgetBase::getLabel public function Return label.
VotingApiWidgetBase::getResults public function Get results.
VotingApiWidgetBase::getValues public function Return minimal value.
VotingApiWidgetBase::getVoteSummary public function Generate summary.
VotingApiWidgetBase::getWindow public function Get time window settings.
VotingApiWidgetBase::__construct public function Constructs a new class instance. Overrides PluginBase::__construct