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.
Extracted from #1626584: Combine configuration system changes to verify they are compatible
Problem
- Various code needs to check whether the config object returned by
config('foo.bar')
already exists or not, but has no way to do so.
Goal
- Allow code to check
$config->isNew()
to determine storage status.
Proposed solution
- Add public
Config::isNew()
method. - Change configuration storage controllers to make a difference between non-existing and existing storage items/records/entries.
Notes
- Config::isNew() is consistent with Entity::isNew(). There is no correlation between Config objects and entities otherwise, but this is good for DX nevertheless.
- Both #1609760: hook_image_style_*() is not invoked for image styles upon Image module installation and #1447686: Allow importing and synchronizing configuration when files are updated might require this new method for handling configuration imports. While that is not clear yet, this patch here already shows the need for it in Image module.
Comment | File | Size | Author |
---|---|---|---|
#3 | config.isnew_.3.patch | 11.15 KB | sun |
#3 | interdiff.txt | 908 bytes | sun |
#2 | 1666632_2.patch | 10.45 KB | chx |
#2 | interdiff.txt | 669 bytes | chx |
#1 | config.isnew_.1.patch | 10.28 KB | sun |
Comments
Comment #1
sunbd79424 Fixed fatal error in image_style_load().
Comment #2
chx CreditAttribution: chx commentedI like this but I have made Config::load() just a little bit more explicit to make it more readable. (Previous patch was testing for $data === FALSE twice)
Comment #3
sunJust ran across another @todo that should be killed by this patch.
3d05a48 Leverage isNew() in image_style_save(), too.
Leaving RTBC, since that change is trivial.
Comment #4
chx CreditAttribution: chx commentedOh great!
Comment #5
webchickMakes sense to me.
Committed and pushed to 8.x. Thanks!
Comment #6.0
(not verified) CreditAttribution: commentedUpdated issue summary.