Useless method overrides in \Drupal\Core\TypedData\PrimitiveBase and missing property definition in TypedData

Created on 6 September 2023, over 1 year ago
Updated 9 September 2023, over 1 year ago

Problem/Motivation

Method overrides for \Drupal\Core\TypedData\PrimitiveBase::getValue() and ::setValue() are useless, they are exactly the same as \Drupal\Core\TypedData\TypedData::getValue() and ::setValue().

Also, PrimitiveBase define $value property, which should be in TypedData? The TypedData is also trying to write and read from that property, but never defines it.

Proposed resolution

Remove useless overrides or provide an explanation why are these overrides exactly the same. Decide what to do with $value property and provide an explanation if needed, why is it defined later on.

Remaining tasks

  • Decide what to do with useless method overrides.
  • Decide what to do with wrong place of $value property definition.
πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
Typed dataΒ  β†’

Last updated 13 days ago

  • Maintained by
  • πŸ‡¦πŸ‡ΉAustria @fago
Created by

πŸ‡·πŸ‡ΊRussia niklan Russia, Perm

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @niklan
  • πŸ‡·πŸ‡ΊRussia niklan Russia, Perm

    Test that simply shows that it can lead to a problem with undefined $value property.

  • Status changed to Needs review over 1 year ago
  • last update over 1 year ago
    30,131 pass, 2 fail
  • πŸ‡·πŸ‡ΊRussia niklan Russia, Perm
  • πŸ‡·πŸ‡ΊRussia niklan Russia, Perm
  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Believe to remove the functions they would have to be deprecated no?

  • πŸ‡·πŸ‡ΊRussia niklan Russia, Perm

    I'm not sure, especially considering that PrimitiveBase is an abstract class that extends another abstract class TypedData with exact same methods, and logic inside.

    Maybe we should do overwise, remove logic of these methods from TypedData? Just make them simply abstract and empty? Because for now they are simply broken (which test is shows): they assume that $value property is presented, but it is not defined by it, and I don't think it should define it as well. But in this case we have to refactor some other classes which extends TypedData.

    For example, \Drupal\Core\Config\Schema\Element extends TypedData directly, because of the problem, it also defines $value property which is makes no sense and just extra code, it should extend PrimitiveBase or provide custom setter and getter, because if TypedData at some point will be changed, it will break. This all a little bit confusing, because TypedData using a property that it doesn't define, and other code define it for it, but we also have PrimitiveBase that does that and duplicate methods as well.

Production build 0.71.5 2024