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