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
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\votingapi_widgets\Plugin\VotingApiWidgetBase implements ContainerFactoryPluginInterface, VotingApiWidgetInterface
- class \Drupal\votingapi_widgets\Plugin\votingapi_widget\FiveStarWidget uses StringTranslationTrait
- class \Drupal\votingapi_widgets\Plugin\VotingApiWidgetBase implements ContainerFactoryPluginInterface, VotingApiWidgetInterface
Expanded class hierarchy of FiveStarWidget
File
- src/
Plugin/ votingapi_widget/ FiveStarWidget.php, line 23
Namespace
Drupal\votingapi_widgets\Plugin\votingapi_widgetView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FiveStarWidget:: |
public | function |
Vote form. Overrides VotingApiWidgetInterface:: |
|
FiveStarWidget:: |
public | function |
Get initial element. Overrides VotingApiWidgetBase:: |
|
FiveStarWidget:: |
public | function |
Get available styles. Overrides VotingApiWidgetInterface:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
VotingApiWidgetBase:: |
protected | property | The user account. | |
VotingApiWidgetBase:: |
protected | property | The config factory service. | |
VotingApiWidgetBase:: |
protected | property | The entity form builder service. | |
VotingApiWidgetBase:: |
protected | property | The entity type manager service. | |
VotingApiWidgetBase:: |
protected | property | The request stack. | |
VotingApiWidgetBase:: |
protected | property | Vote result function manager service. | |
VotingApiWidgetBase:: |
public | function | Checks whether currentUser is allowed to vote. | |
VotingApiWidgetBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
VotingApiWidgetBase:: |
public | function | Returns a Vote entity. | |
VotingApiWidgetBase:: |
public | function | Gets the widget form as configured for given parameters. | |
VotingApiWidgetBase:: |
public | function | Return label. | |
VotingApiWidgetBase:: |
public | function | Get results. | |
VotingApiWidgetBase:: |
public | function | Return minimal value. | |
VotingApiWidgetBase:: |
public | function | Generate summary. | |
VotingApiWidgetBase:: |
public | function | Get time window settings. | |
VotingApiWidgetBase:: |
public | function |
Constructs a new class instance. Overrides PluginBase:: |