In order for JSON API to work correctly, the UUID field needs to be added to the votingapi_result table. This issue is essentially a re-roll of the work done by sylus in https://www.drupal.org/project/votingapi/issues/2872435#comment-12131648. It was removed from that issue because it wasn't directly related to it.

Issue fork votingapi-2965603

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jeffdavidgordon created an issue. See original summary.

jeffdavidgordon’s picture

StatusFileSize
new4.87 KB

Here is the first patch to address this issue.

jeffdavidgordon’s picture

StatusFileSize
new4.81 KB

Re-rolling against alpha7.

pifagor’s picture

Assigned: jeffdavidgordon » Unassigned
Status: Active » Needs review
pifagor’s picture

Status: Needs review » Needs work

Patch Failed to Apply

Vidushi Mehta’s picture

Status: Needs work » Needs review
StatusFileSize
new4.85 KB

Rerolled again.

tr’s picture

Status: Needs review » Needs work

Patch no longer applies and needs to be rerolled.

goz made their first commit to this issue’s fork.

goz’s picture

Status: Needs work » Needs review
StatusFileSize
new5.64 KB

I need this to make vote_result entities available with jsonapi.

Here is a patch update for last 8.3.x and Drupal 10.

UUID is a requirement to make entities available on JSONAPI. An issue on core deal with a better way to detect an entity has missing UUID #3090253: Detect when UUID is missing and provide better exception/error message when constructing a JSON:API payload but UUID will still be required.

tr’s picture

Version: 8.x-3.x-dev » 4.0.x-dev
Status: Needs review » Needs work
Issue tags: -UUID +Needs tests

This patch has some problems. For example:

@@ -130,6 +132,11 @@ class VoteResult extends ContentEntityBase implements VoteResultInterface {
       ->setReadOnly(TRUE)
       ->setSetting('unsigned', TRUE);
 
+    $fields[$entity_type->getKey('uuid')] = BaseFieldDefinition::create('uuid')
+      ->setLabel(new TranslatableMarkup('UUID'))
+      ->setDescription(new TranslatableMarkup('The vote result UUID.'))
+      ->setReadOnly(TRUE);
+

This is not right because the parent ContentEntityBase creates the base field for uuid as long as the entity key is set. That code should not be duplicated here. Also see #3153550: Vote entity unnecessarily re-implements features provided by base class for similar problems with the Vote entity.

Both Vote and VoteResult were written early in D8 before a lot of functionality was moved into ContentEntityBase. So now they both need some major work. And it's important to do that work in a way that won't break existing sites. Because of that, this change should be done in the 4.0.x branch only and have update tests so that we can ensure the entity structure isn't being broken for people upgrading from 8.x-3.x.

goz’s picture

I agree. Entity should not duplicate base fields but extends and use ContentEntityBase.

However, while #3153550: Vote entity unnecessarily re-implements features provided by base class is not fixed, if someone needs uuid support, the current patch and issue add it. We cannot do better in this issue without big changes in the module

tr’s picture

Status: Needs work » Active

tr changed the visibility of the branch 2965603-add-support-for to hidden.

tr’s picture

Status: Active » Needs work

I created a MR for the 4.0.x branch.
This will not be put into the 8.x-3.x branch.

Note that the tests fail (in both the new MR and the old MR) because the new uuid field is not being initialized. This would not happen if VoteResult simply inherited the uuid field from ContentEntityBase.

Like I said, instead of defining our own new base field, we should just add the uuid entity key and call parent::baseFieldDefinitions(); so that ContentEntityBase will define and handle the uuid field.

This fix is needed before we can release 4.0.0.