UsefulWidget.php in Votingapi Widgets 8
File
src/Plugin/votingapi_widget/UsefulWidget.php
View source
<?php
namespace Drupal\votingapi_widgets\Plugin\votingapi_widget;
use Drupal\votingapi_widgets\Plugin\VotingApiWidgetBase;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class UsefulWidget extends VotingApiWidgetBase {
use StringTranslationTrait;
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;
}
public function getInitialVotingElement(array &$form) {
$form['value']['#prefix'] = '<div class="votingapi-widgets useful">';
$form['value']['#attached'] = [
'library' => [
'votingapi_widgets/useful',
],
];
$form['value']['#suffix'] = '</div>';
}
public function getStyles() {
return [
'default' => $this
->t('Default'),
];
}
}