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.
It turned out in #2015697-19: Convert field type to typed data plugin for file and image modules that ImageItem::getFieldSetting('default_image')
is returning a wrong FID for default image file. This happens only in field settings (not in instance settings). getFieldSetting()
was introduced in #1950632: Create a FieldDefinitionInterface and use it for formatters and widgets.
I manually tested and the field setting is returning the instance setting for some unclear reasons.
Related issues
Comment | File | Size | Author |
---|---|---|---|
#17 | 2060003-17.patch | 4.02 KB | claudiu.cristea |
#17 | interdiff.txt | 3.05 KB | claudiu.cristea |
#14 | 2060003-13.patch | 5.01 KB | claudiu.cristea |
#14 | interdiff.txt | 1.62 KB | claudiu.cristea |
#12 | 2060003-12.patch | 4.66 KB | claudiu.cristea |
Comments
Comment #1
claudiu.cristeaHere's a test demonstrating this bug. Should be red showing that instance passes but field not.
Comment #2
claudiu.cristeaComment #4
yched CreditAttribution: yched commentedIndeed, Field::getSetting() looks wrong.
It should first look if the setting is present in the actual settings of the field, then fetch a 'default field-level value', then fetch a 'default instance-level value'.
Comment #5
claudiu.cristeaHmm. We should test
getFieldSettings()
too. Not very sure but as I remember it fails there too.Comment #6
yched CreditAttribution: yched commentedActually, getFieldSettings() will have the same logic issue.
Interdiff is against #1, contains the whole fix.
Comment #7
claudiu.cristeaAh! Crossposting :)
Yes, let's add
getFieldSettings()
to tests too and provide a failure patch also to prove all scenarios.Comment #8
claudiu.cristeaHere is an updated test, extend to
Field::getFieldSettings()
.The patch
2060003-8-fail.patch
should be red,2060003-8-pass.patch
green. Interdiff against #1 only for tests.Comment #9
claudiu.cristeaRemoved trailing spaces only from
2060003-8-pass.patch
.Comment #10
claudiu.cristeaSorry :)
Comment #11
yched CreditAttribution: yched commentedNot sure about
<code>
tags in simpletest messages :-)The grammar seems a bit off too:
"Article image field instance default equals expected file ID of @fid, returned @returned by
FieldInstance::getFieldSetting('default_image')"
-> "Article setting returned by FieldInstance::getFieldSetting(): @returned; expected: @fid" ?
Comment #12
claudiu.cristeaOK.
Comment #14
claudiu.cristeaMessed up
format_string()
arguments :)Comment #15
claudiu.cristeaTurned green and looks good. This is blocking #2015697: Convert field type to typed data plugin for file and image modules -- any takers for review and/or rtbc?
Comment #16
BerdirI'm not sure how useful these assertion messages are. the expected/returned values are printed by the default output too.
The advantage of leaving it out would be that you could write the assertEqual() arguments on a single line and avoid any arguments about multiline function arguments... ;)
Nitpick: I think this reads more fluent if you write Also test FieldInstance::getFieldSettings(). Not sure if this should use the full namespace.
Comment #17
claudiu.cristeaYes. Thinking that we'll drop them in the future when moving to phpunit let's drop them here too.
Comment #18
claudiu.cristeaOK. Turned green :)
Comment #19
BerdirLovely. I think this is good, test is much more readable like this IMHO.
Comment #20
catchCommitted/pushed to 8.x, thanks!
Comment #22
claudiu.cristeaIMO, we need to explain somehow what's happen if the filed setting and instance setting share the same name. I expect
getFieldSettings()
to magically return the right value in the given context. I think we need one of these:OR
getFieldSettings()
to avoid name collision in usage.Should we open a followup?
EDIT (added): See #2015697-31: Convert field type to typed data plugin for file and image modules for details.
Comment #23
yched CreditAttribution: yched commented@claudiu.cristea: OK, I opened #2074217: Reconsider support for field-level & instance-level settings with the same name ? for discussion - and copied over the reasons why I think that is a non-issue ;-)
Comment #24
claudiu.cristeaThen let's close this.
Comment #24.0
claudiu.cristeaLink to correct issue