Problem/Motivation

Forgot to create a follow-up from #2648802: Deleting a choice should delete the votes over it in the database (?) (see #6).

lets do a follow-up to move all vote related methods from PollStorage to this new service.

Proposed resolution

- move these methods from PollStorage to PollVoteStorage
- update the affected classes

Remaining tasks

User interface changes

API changes

Data model changes

Comments

tduong created an issue. See original summary.

tduong’s picture

Assigned: Unassigned » tduong
Status: Active » Needs review
StatusFileSize
new14.37 KB

Moved the methods, updated affected Interfaces and classes, + small refactorings.

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/src/Entity/Poll.php
    @@ -379,7 +379,8 @@ class Poll extends ContentEntityBase implements PollInterface {
    -    $poll_storage_controller = \Drupal::entityManager()->getStorage('poll');
    +    /** @var \Drupal\poll\PollVoteStorage $poll_storage_controller */
    +    $poll_storage_controller = \Drupal::service('poll_vote.storage');
         return $poll_storage_controller->getUserVote($this);
    

    You should update the variable name. it's no longer a storage_controller. Just $vote_storage.

  2. +++ b/src/PollStorageInterface.php
    @@ -16,61 +15,6 @@ use Drupal\Core\Session\AccountInterface;
    -   * Save a user's vote.
    -   *
    -   * @param array $options
    -   *
    -   * @return mixed
    -   */
    -  public function saveVote(array $options);
    

    Poll has a beta release. That means we should not change the API like this, it might break custom and other contrib modules.

    So what we have to do is add a @deprecated text, see examples in core and say that this was deprecated in 8.x-1.0 and XYZ should be used instead. Then also keep the old implementations and call the new methods instead.

  3. +++ b/src/PollVoteStorage.php
    @@ -2,17 +2,19 @@
    -class PollVoteStorage implements PollVoteStorageInterface {
    +class PollVoteStorage extends SqlContentEntityStorage implements PollVoteStorageInterface {
    

    this is not an entity storage. Don't extend from that.

  4. +++ b/src/PollVoteStorageInterface.php
    @@ -2,15 +2,18 @@
    -interface PollVoteStorageInterface {
    +interface PollVoteStorageInterface extends EntityStorageInterface {
     
    

    same here. we just have our own methods, nothing else.

tduong’s picture

Status: Needs work » Needs review
StatusFileSize
new9.99 KB
new15.64 KB

Fixed based on comment above.

berdir’s picture

+++ b/src/Plugin/views/field/PollTotalVotes.php
@@ -23,8 +23,9 @@ class PollTotalVotes extends FieldPluginBase {
     $entity = $values->_entity;
-    return  $pollStorage->getTotalVotes($entity);
+    return  $vote_storage->getTotalVotes($entity);

double space here, lets fix it while we touch the code.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

I'll fix that on commit.

berdir’s picture

Status: Reviewed & tested by the community » Fixed

Thank you.

  • Berdir committed 385a837 on 8.x-1.x authored by tduong
    Issue #2682423 by tduong: Move all vote related methods from PollStorage...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.