class UsefulWidget in Votingapi Widgets 8
Assigns ownership of a node to a user.
Plugin annotation
@VotingApiWidget(
id = "useful",
label = @Translation("Useful rating"),
values = {
-1 = @Translation("Not useful"),
1 = @Translation("Useful"),
},
)
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\UsefulWidget uses StringTranslationTrait
- class \Drupal\votingapi_widgets\Plugin\VotingApiWidgetBase implements ContainerFactoryPluginInterface, VotingApiWidgetInterface
Expanded class hierarchy of UsefulWidget
File
- src/
Plugin/ votingapi_widget/ UsefulWidget.php, line 20
Namespace
Drupal\votingapi_widgets\Plugin\votingapi_widgetView source
class UsefulWidget 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',
'useful',
$settings['readonly'] === 1 ? 'read_only' : '',
],
],
'#children' => [
'form' => $form,
],
],
'#attached' => [
'library' => [
'votingapi_widgets/useful',
],
],
];
return $build;
}
/**
* {@inheritdoc}
*/
public function getInitialVotingElement(array &$form) {
$form['value']['#prefix'] = '<div class="votingapi-widgets useful">';
$form['value']['#attached'] = [
'library' => [
'votingapi_widgets/useful',
],
];
$form['value']['#suffix'] = '</div>';
}
/**
* {@inheritdoc}
*/
public function getStyles() {
return [
'default' => $this
->t('Default'),
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
UsefulWidget:: |
public | function |
Vote form. Overrides VotingApiWidgetInterface:: |
|
UsefulWidget:: |
public | function |
Get initial element. Overrides VotingApiWidgetBase:: |
|
UsefulWidget:: |
public | function |
Get available styles. Overrides VotingApiWidgetInterface:: |
|
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:: |