Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When using the \Drupal\field\Entity\FieldStorageConfig::loadByName()
method, the returned results don't match the return type given in the DocBlock comment. This has lead to us having an uncaught exception that we didn't expect.
Proposed resolution
Fix up the return type documented in the DocBlock to improve the DX and help catch problems before they happen.
Remaining tasks
None.
Comment | File | Size | Author |
---|---|---|---|
#16 | incorrect_return_type-2918290-16.patch | 1.77 KB | somersoft |
#4 | incorrect_return_type-2918290-4.patch | 589 bytes | chOP |
Comments
Comment #2
chOP CreditAttribution: chOP at Deloitte Digital commentedI've corrected return types for this method. Please review.
The return type here should be consistent with
\Drupal\Core\Entity\EntityStorageInterface::load()
as we're simply returning a result from that interface implementation.Comment #3
chOP CreditAttribution: chOP at Deloitte Digital commentedComment #4
chOP CreditAttribution: chOP at Deloitte Digital commentedOkay, I've reviewed the return type and adjusted it to more accurately reflect the actual interface that can be expected.
The method will return
\Drupal\field\FieldStorageConfigInterface
or null. TheFieldStorageConfigInterface
is an extended implementation of theEntityInterface
.Please review this updated patch.
Comment #5
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThe current coding standards say that this could be simply
@return $this
without any description :)Comment #6
chOP CreditAttribution: chOP at Deloitte Digital commented@amateescu:
But that is not what it returns. It returns an object, or null, by loading from another Class's static method. I could understand putting
@return $this
if that's what the method did, but it doesn't. This is a static method, so it cannot return $this. Nor does it ever return itself, the static class.If you said
@return $this
you'd be expecting that this method returned a reference to the instance of itself. It doesn't do that. It returns a reference to an entirely different object instance.Comment #7
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented@chOP, right, you have a very good point :)
Would you be ok with fixing the return documentation for
\Drupal\field\Entity\FieldConfig::loadByName()
and\Drupal\Core\Field\Entity\BaseFieldOverride::loadByName
in this issue?Comment #9
borisson_#7 needs to be fixed before we can get this in.
Comment #14
somersoft CreditAttribution: somersoft commentedAdd the reqest change in #7 .
These changes help with removing false errors when running the Drupal check program.
Comment #15
longwave#14 covers
\Drupal\field\Entity\FieldStorageConfig::loadByName()
but not\Drupal\field\Entity\FieldConfig::loadByName()
as requested in #7.Comment #16
somersoft CreditAttribution: somersoft commentedSorry, I have now added the requested document change.
In my code base the Base Field Override is called and hence retaining that change as well.
Comment #17
longwaveThanks, this looks good now.
Comment #19
longwaveQuickEditIntegrationTest strikes again.
Comment #21
catchCommitted 83fcced and pushed to 9.1.x. Thanks!