Machine name looks hardcoded

Created on 11 December 2017, almost 7 years ago
Updated 11 August 2024, 3 months ago

It seems the module is expecting the machine name of the fields to be hardcoded, and there is no option to use the widget for any field with 'custom' machine name. Don't see the purpose of doing this. I may be missing something. I will apply the patch that removes the conditional check for machine name and works for voting API fields with any machine name.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡²πŸ‡©Moldova the.tai.pen@gmail.com

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    The commit in #4 was immediately reverted by commit df19319cd23fc816 without that revert being mentioned here, and without discussion, and without an issue for the reversion.

    As a result, the problem pointed out by the original poster still exists today, more than 5 years later. And the problem is very clear. In the existing code we have:

      public function getVoteSummary(ContentEntityInterface $vote) {
        $results = $this->getResults($vote);
        $field_name = $vote->field_name->value;

    This is one of several parts of the code that make huge assumptions. Specifically, "field_name", as used here, does not do anything and does not work. And the intent of this last line of code is suspect - why is a variable named $field_name being set to the value of a field named "field_name" ? First, there is no field named "field_name". All we know about $vote is that it is a generic ContentEntityInterface - we don't even know that the entity is fieldable. And even if that generic entity holds a vote, we don't know the name of the field where that vote is store. But it's certainly NOT named "field_name". Second, if the variable is to hold a value, it should be named $field_value or something like that - what is the purpose of this line?

    In short, this is still very much a problem. We absolutely need to look into all the uses of "$entity->field_name" in this module because none of them make any sense. I suspect these are a legacy of how the D7 version of this module worked.

    And this also underscores the need for TEST CASES. This getVoteSummary() method, for example, should have a simple test case to demonstrate that it returns the expected result - it clearly doesn't.

  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia
Production build 0.71.5 2024