diff --git a/composer.json b/composer.json index 7b03746..367959d 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,6 @@ "source": "https://git.drupalcode.org/project/fivestar" }, "require": { - "drupal/core": "^8.8.2 || ^9", "drupal/votingapi": "^3.0" }, "minimum-stability": "dev" diff --git a/fivestar.info.yml b/fivestar.info.yml index 38a88d7..fb1048f 100644 --- a/fivestar.info.yml +++ b/fivestar.info.yml @@ -2,8 +2,7 @@ name: Fivestar type: module description: 'Enables fivestar ratings on content, users, etc.' package: Voting -core_version_requirement: ^8.8.2 || ^9 +core_version_requirement: ^9.3 || ^10 dependencies: - votingapi:votingapi - configure: fivestar.admin_overview diff --git a/fivestar.libraries.yml b/fivestar.libraries.yml index 1e829b7..218cd84 100644 --- a/fivestar.libraries.yml +++ b/fivestar.libraries.yml @@ -9,7 +9,7 @@ fivestar.base: dependencies: - core/jquery - core/drupal - - core/jquery.once + - core/once - core/drupal.ajax fivestar.admin: @@ -25,7 +25,7 @@ fivestar.ajax: dependencies: - core/jquery - core/drupal - - core/jquery.once + - core/once # Widgets # Right now does not include RTL handling diff --git a/src/Element/Fivestar.php b/src/Element/Fivestar.php index 15d4a6d..287f148 100644 --- a/src/Element/Fivestar.php +++ b/src/Element/Fivestar.php @@ -262,10 +262,10 @@ class Fivestar extends FormElement { // Check if user have votes in current entity type. $vote_ids = []; $current_user = \Drupal::currentUser(); - $entity_type = isset($element['#settings']['content_type']) ? $element['#settings']['content_type'] : NULL; - $entity_id = isset($element['#settings']['content_id']) ? $element['#settings']['content_id'] : NULL; + $entity_type = isset($element['#settings']['entity_type']) ? $element['#settings']['entity_type'] : NULL; + $entity_id = isset($element['#settings']['entity_id']) ? $element['#settings']['entity_id'] : NULL; - if (!$entity_type || !$entity_id) { + if ($entity_type && $entity_id) { $vote_ids = \Drupal::entityQuery('vote') ->condition('entity_type', $entity_type) ->condition('entity_id', $entity_id) @@ -274,7 +274,7 @@ class Fivestar extends FormElement { } // If user voted before, return FALSE. - if (empty($vote_ids)) { + if (!empty($vote_ids)) { return FALSE; } diff --git a/src/Form/FivestarForm.php b/src/Form/FivestarForm.php index 3ceba8d..c407322 100644 --- a/src/Form/FivestarForm.php +++ b/src/Form/FivestarForm.php @@ -62,6 +62,11 @@ class FivestarForm extends FormBase { $field_name = $field_definition->getName(); $voting_is_allowed = (bool) ($field_settings['rated_while'] == 'viewing'); + // Extend display settings by entity_type and id. + $settings = $context['display_settings']; + $settings['entity_type'] = $entity->getEntityTypeId(); + $settings['entity_id'] = $entity->id(); + $form['vote'] = [ '#type' => 'fivestar', '#stars' => $field_settings['stars'], @@ -72,7 +77,7 @@ class FivestarForm extends FormBase { '#widget' => $context['display_settings'], '#default_value' => $entity->get($field_name)->rating, '#values' => $this->resultManager->getResultsByVoteType($entity, $field_settings['vote_type']), - '#settings' => $context['display_settings'], + '#settings' => $settings, '#show_static_result' => !$voting_is_allowed, '#attributes' => [ 'class' => ['vote'], diff --git a/tests/src/Functional/FivestarTest.php b/tests/src/Functional/FivestarTest.php index 7f69f0b..47672e8 100644 --- a/tests/src/Functional/FivestarTest.php +++ b/tests/src/Functional/FivestarTest.php @@ -48,7 +48,7 @@ class FivestarTest extends BrowserTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); // Create content type for testing. @@ -142,7 +142,7 @@ class FivestarTest extends BrowserTestBase { // Rate the test_node_type. $this->drupalLogin($this->voterUser); $this->drupalGet('node/' . $node->id()); - $this->assertRaw('No votes yet', 'Fivestar field has no votes.'); + $this->assertSession()->responseContains('No votes yet'); $this->assertEmpty($this->xpath("//form[contains(@class, 'fivestar-widget')]")); // Check if node with attached fivestar field can be save. diff --git a/tests/src/FunctionalJavascript/FivestarAjaxTestBase.php b/tests/src/FunctionalJavascript/FivestarAjaxTestBase.php index 82487e4..e9a07f9 100644 --- a/tests/src/FunctionalJavascript/FivestarAjaxTestBase.php +++ b/tests/src/FunctionalJavascript/FivestarAjaxTestBase.php @@ -47,7 +47,7 @@ abstract class FivestarAjaxTestBase extends WebDriverTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); // Create content type for testing. diff --git a/tests/src/Kernel/HookFivestarWidgetsAlterTest.php b/tests/src/Kernel/HookFivestarWidgetsAlterTest.php index 53c0c45..cd83e69 100644 --- a/tests/src/Kernel/HookFivestarWidgetsAlterTest.php +++ b/tests/src/Kernel/HookFivestarWidgetsAlterTest.php @@ -30,7 +30,7 @@ class HookFivestarWidgetsAlterTest extends KernelTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->widgetManager = $this->container->get('fivestar.widget_manager'); diff --git a/tests/src/Kernel/HookFivestarWidgetsTest.php b/tests/src/Kernel/HookFivestarWidgetsTest.php index 88bc193..0ac0146 100644 --- a/tests/src/Kernel/HookFivestarWidgetsTest.php +++ b/tests/src/Kernel/HookFivestarWidgetsTest.php @@ -30,7 +30,7 @@ class HookFivestarWidgetsTest extends KernelTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->widgetManager = $this->container->get('fivestar.widget_manager');