You are here

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

Expanded class hierarchy of UsefulWidget

File

src/Plugin/votingapi_widget/UsefulWidget.php, line 20

Namespace

Drupal\votingapi_widgets\Plugin\votingapi_widget
View 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

Namesort descending Modifiers Type Description Overrides
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.
UsefulWidget::buildForm public function Vote form. Overrides VotingApiWidgetInterface::buildForm
UsefulWidget::getInitialVotingElement public function Get initial element. Overrides VotingApiWidgetBase::getInitialVotingElement
UsefulWidget::getStyles public function Get available styles. Overrides VotingApiWidgetInterface::getStyles
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