Skip to content
Snippets Groups Projects
Commit d2f64a80 authored by Tim Rohaly's avatar Tim Rohaly
Browse files

Merge branch '3507935-add-typing-to' into '2.0.x'

Issue #3507935 by tr: Add typing to VotingApiWidgets plugins and manager

See merge request !26
parents c2d1964e 9f6a9ea6
No related branches found
No related tags found
No related merge requests found
Pipeline #432108 failed
<?php
declare(strict_types=1);
namespace Drupal\votingapi_widgets\Plugin\VotingApiWidget;
use Drupal\Core\StringTranslation\StringTranslationTrait;
......@@ -39,7 +41,7 @@ class FiveStarWidget extends VotingApiWidgetBase {
/**
* Vote form.
*/
public function buildForm($entity_type, $entity_bundle, $entity_id, $vote_type, $field_name, $settings) {
public function buildForm(string $entity_type, string $entity_bundle, string|int $entity_id, string $vote_type, string $field_name, array $settings): array {
$form = $this->getForm($entity_type, $entity_bundle, $entity_id, $vote_type, $field_name, $settings);
$build = [
'rating' => [
......@@ -80,7 +82,7 @@ class FiveStarWidget extends VotingApiWidgetBase {
/**
* {@inheritdoc}
*/
public function getStyles() {
public function getStyles(): array {
return [
'default' => $this->t('Default'),
'bars-horizontal' => $this->t('Bars horizontal'),
......
<?php
declare(strict_types=1);
namespace Drupal\votingapi_widgets\Plugin\VotingApiWidget;
use Drupal\Core\StringTranslation\StringTranslationTrait;
......@@ -31,7 +33,7 @@ class LikeWidget extends VotingApiWidgetBase {
/**
* Vote form.
*/
public function buildForm($entity_type, $entity_bundle, $entity_id, $vote_type, $field_name, $settings) {
public function buildForm(string $entity_type, string $entity_bundle, string|int $entity_id, string $vote_type, string $field_name, array $settings): array {
$form = $this->getForm($entity_type, $entity_bundle, $entity_id, $vote_type, $field_name, $settings);
$build = [
'rating' => [
......@@ -68,7 +70,7 @@ class LikeWidget extends VotingApiWidgetBase {
/**
* {@inheritdoc}
*/
public function getStyles() {
public function getStyles(): array {
return [
'default' => $this->t('Default'),
];
......
<?php
declare(strict_types=1);
namespace Drupal\votingapi_widgets\Plugin\VotingApiWidget;
use Drupal\Core\StringTranslation\StringTranslationTrait;
......@@ -33,7 +35,7 @@ class UsefulWidget extends VotingApiWidgetBase {
/**
* Vote form.
*/
public function buildForm($entity_type, $entity_bundle, $entity_id, $vote_type, $field_name, $settings) {
public function buildForm(string $entity_type, string $entity_bundle, string|int $entity_id, string $vote_type, string $field_name, array $settings): array {
$form = $this->getForm($entity_type, $entity_bundle, $entity_id, $vote_type, $field_name, $settings);
$build = [
'rating' => [
......@@ -70,7 +72,7 @@ class UsefulWidget extends VotingApiWidgetBase {
/**
* {@inheritdoc}
*/
public function getStyles() {
public function getStyles(): array {
return [
'default' => $this->t('Default'),
];
......
<?php
declare(strict_types=1);
namespace Drupal\votingapi_widgets\Plugin;
use Drupal\Component\Plugin\PluginBase;
......@@ -112,16 +114,16 @@ abstract class VotingApiWidgetBase extends PluginBase implements VotingApiWidget
}
/**
* Return label.
* {@inheritdoc}
*/
public function getLabel() {
return $this->label;
public function getLabel(): string {
return (string) $this->getPluginDefinition()['label'];
}
/**
* Return minimal value.
* {@inheritdoc}
*/
public function getValues() {
public function getValues(): array {
return $this->getPluginDefinition()['values'];
}
......@@ -131,7 +133,7 @@ abstract class VotingApiWidgetBase extends PluginBase implements VotingApiWidget
* @return array
* Configured vote form.
*/
public function getForm($entity_type, $entity_bundle, $entity_id, $vote_type, $field_name, $settings) {
public function getForm(string $entity_type, string $entity_bundle, string|int $entity_id, string $vote_type, string $field_name, array $settings): array {
$vote = $this->getEntityForVoting($entity_type, $entity_bundle, $entity_id, $vote_type, $field_name);
/*
* @todo Remove custom entity_form_builder once
......@@ -261,7 +263,7 @@ abstract class VotingApiWidgetBase extends PluginBase implements VotingApiWidget
}
/**
* Get time window settings.
* Gets time window settings.
*/
public function getWindow($window_type, $entity_type_id, $entity_bundle, $field_name) {
$config = FieldConfig::loadByName($entity_type_id, $entity_bundle, $field_name);
......
......@@ -5,18 +5,60 @@ namespace Drupal\votingapi_widgets\Plugin;
use Drupal\Component\Plugin\PluginInspectionInterface;
/**
* Defines an interface for Voting api widget plugins.
* Defines an interface for Voting API widget plugins.
*/
interface VotingApiWidgetInterface extends PluginInspectionInterface {
/**
* Build form.
* Builds the widget form.
*
* @param string $entity_type
* @param string $entity_bundle
* @param string|int $entity_id
* @param string $vote_type
* @param string $field_name
* @param array $settings
*
* @return array
* The form array for the widget.
*/
public function buildForm($entity_type, $entity_bundle, $entity_id, $vote_type, $field_name, $settings);
public function buildForm(string $entity_type, string $entity_bundle, string|int $entity_id, string $vote_type, string $field_name, array $settings): array;
/**
* Get available styles.
* Gets available widget styles.
*
* @return array
* An associative array of widget styles. Keys are the CSS style file name,
* values are the human-readable name for the style.
*/
public function getStyles();
public function getStyles(): array;
/**
* Gets the translated label from the plugin definition.
*
* @return string
* The label of the plugin.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* Thrown if the label is not defined for the plugin.
*/
public function getLabel(): string;
/**
* Gets allowed widget values.
*
* @return array
* An array of allowed values. Each value holds the translated short
* description of a style.
*/
public function getValues(): array;
/**
* Gets the initial element.
*
* @param array &$form
* The form array to modify.
*/
public function getInitialVotingElement(array &$form);
}
<?php
declare(strict_types=1);
namespace Drupal\votingapi_widgets\Plugin;
use Drupal\Core\Cache\CacheBackendInterface;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment