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.
Goal
- Convert image styles $style array into ImageStyle (extends ConfigEntity).
Part of #1802750: [Meta] Convert configurable data to ConfigEntity system
Details
- $style becomes a classed object,
Drupal\image\ImageStyle
. - Wherever the code refers to the style ID, use
$style->id()
. - Wherever the code intends to output a label for the image style, use
$style->label()
. (There is a true label via #606598: Human readable image-style names)
Notes
- This should be relatively straightforward to do, so tentatively tagging with Config Novice.
Related issues
- Example conversion: #1588422: Convert contact categories to configuration system & #1552396: Convert vocabularies into configuration
- #1781372: Add an API for listing (configuration) entities
- #1805928: Convert theme_image_style_list
- #1788918: [GTD] [META] Prepare for Twig main engine core inclusion until December 1
Follow-ups
#1818702: Get rid of image_style_delete()
#1788542: Use EntityFormController and EntityListController for image styles
#1809376: Use EntityListController for image styles
#1821848: Move image style load/update/delete operations into a new ImageStyleStorageController
#1821854: Convert image effects into plugins
#1821534: Can't delete image effects from an image style
Comment | File | Size | Author |
---|---|---|---|
#68 | 17282244-image-styles-followup-68.patch | 9.86 KB | gdd |
#60 | image-styles-1782244-60.patch | 11.32 KB | tim.plunkett |
#48 | drupal8.image-config.48.patch | 12.34 KB | sun |
#41 | drupal8.image-config.41.patch | 15.09 KB | sun |
#36 | drupal8.image-config.36.patch | 12.94 KB | sun |
Comments
Comment #1
larowlantagging
Comment #2
andypostRelated #1788542: Use EntityFormController and EntityListController for image styles
Could be done after this one
Comment #3
catchThis seems major (at least) to me? Also #1781372: Add an API for listing (configuration) entities is in so we can use that for the image style configuration page now.
Comment #3.0
catchUpdated issue summary.
Comment #4
andypostCan we make it after feature freeze?
Comment #5
xjmDemoting in favor of #1802750: [Meta] Convert configurable data to ConfigEntity system.
Comment #6
tstoecklerI'm going to take a stab at this. If there's no patch until Tuesday, feel free to take this or un-assign.
Comment #7
tstoecklerPosting a WIP patch in order to meet my own deadline. :-)
Works:
* List controller
Doesn't work:
* Form controller
Unassigning. I'll try to bring this home, but I'm not sure if I'll get to it.
Comment #8
gddLooking through this, I'm curious why you changed the path to all the admin urls? For instance, 'edit' is now 'manage', '[style]/delete' is now 'manage/[style]/delete', etc.
Comment #9
gddOK after discussing with xjm and timplunkett in IRC, I learned that it is more semantically proper and standard to go [thing]/[task] rather than the other way around (which is how it was in D7.) An open question to me though is that 'manage' seems unnecessary, we could just go '[style]/edit' etc.
Comment #10
gddI'm grabbing this, I know its marked as novice but it will provide me a good opportunity to get more well versed in config entities.
Comment #10.0
gddUpdated issue summary.
Comment #11
xjmMeta issue for these: #1802750: [Meta] Convert configurable data to ConfigEntity system
Comment #12
andypostThis issue also should kill one theme function - replace with listController, related issue #1805928: Convert theme_image_style_list
Comment #12.0
andypostAdded link to meta issue
Comment #13
tstoecklerWell we need the 'manage' in there, because otherwise we have the following menu routers:
admin/config/media/image-style/%image_style
admin/config/media/image-style/add
So you inherently can't name an image style 'add'. In general, I think we should try to avoid both wildcards and static paths on the same level of a menu tree. We do the same thing for node types and currently for the config test entity.
The reason I changed this in the first place is because the list controller appends '/edit' and '/delete' to the entity URIs, to create the operation links. The menu routers before were
admin/config/media/image-style/delete/%image_style
admin/config/media/image-style/edit/%image_style
so that obviously didn't work.
Edit: Where I said "config entity" before, I actually meant "config test entity".
Comment #14
andypost@tstoeckler see #1588422-130: Convert contact categories to configuration system
Comment #15
tstoecklerRight, that shows that they have the same problem over there. They need to change the menu routers as well.
Comment #15.0
tstoecklerAdded twig related issues
Comment #16
gddHere we go. As discussed elsewhere, this is just the conversion to ConfigEntity and does not include the ListController or FormController changes. There are only two other moderately significant changes here
- I removed image_style_effects() because it was totally pointless.
- I removed hook_image_style_alter(). We are going to get rid of it anyways, and it reduced the code in that area. A few months ago I did some research and to the best of my knowledge nobody is using that hook in contrib-land. That said, if someone wants to push that change off to a followup then I'm fine with that too.
Not addressed at all is that we should just remove all the image_effect_*() functions entirely. That is total followup work.
This passes all tests locally.
Comment #18
tim.plunkettThis all looks awesome.
These should all be $style->save()
(and more in the tests)
This should all be removed, and use hook_image_style_presave() that is triggered by ConfigStorageController::save()
Ideally the same for here, but I'm not sure about the replacement style stuff
Trailing whitespace.
The docblock should be "Overrides Drupal\Core\Entity\Entity::id()."
But in reality, Drupal\Core\Entity\Entity::id() should be less stupid and use the entity keys...
Comment #19
gddNot completely sure what happened there
Comment #21
gddCrap I forgot about the upgrade path tests. If someone wants to pick this up at this point, feel free. I may not get back to it within a couple days.
Comment #22
gddAlso, when the change notice for this is written, we should make sure and note the following: Upgrade path will migrate all styles present in the image_styles table. However, it will not update and styles supplied via hook_image_effect_info(). It will be responsibility of the contributed module to supply this style information in a YAML file in the module's config directory.
Comment #23
andypostreverted changes in upgrade path and fixed small whitespace issues
Comment #24
andypostAdded new hooks and a bit cleaned up doc blocks
Removed image_style() image_style_save() so fixed all of #18 except image_style_delete()
Suppose we need to override delete() method of entity and introduce storage controller with this override
EDIT todo:
1) how to deal with alter hook_image_styles_alter()
2) change path for administration could be done in follow-up for form-controller admin/config/media/image-styles/edit/
Comment #25
gddDoes this get called on creates as well as saves?
I think we should leave the delete stuff for now while we work out the replacement style stuff. We have to open a followup to figure out how to deal with that in deployments, so we can address it there.
I also think we are fine removing hook_image_styles_alter() entirely. I've done a reasonably in-depth search of contrib and I haven't found any instances of it being used, and there are none in core. We have been establishing a standard that there are no alters for config as well. Dump it.
Actually shouldn't image.api.php be essentially emptied out? All usages of the hook_image_crud() hooks should move to responding to the appropriate entity hooks so are we repeating them here? They aren't really 'image api' hooks anymore. It seems like the only ones that should stay are
hook_image_effect_info()
hook_image_effect_info_alter() (both of these pending reworking of the image effect api)
hook_image_style_flush()
So other than the doc questions and the one question above I think this is ready to go. I've been testing it quite a bit in accordance with the import UI patch and things are working well.
Comment #26
gddI just talked to jhodgdon about the documentation issue, and she agrees that the hook_ENTITY_NAME_CRUD() hooks should not be documented anywhere outside of entity.api.php. Therefore here is a new patch that removes them. I also verified that an entity create will call hook_entity_name_udpate() so that is no longer an issue. I won't RTBC this patch even though its technically just a docs reroll, but I consider it so.
Comment #27
tim.plunkettThe only ugly part of this patch is the
list(, , $id) = explode('.', $name);
stuff, but that will be addressed in #1760358: Provide a way to extract the ID from a config object name.Everything else looks great!
Comment #27.0
andypostUpdated issue summary.
Comment #28
andypost+1 to RTBC, We need this get commited to proceed with
#1788542: Use EntityFormController and EntityListController for image styles
#1809376: Use EntityListController for image styles
Filed as follow-up #1818702: Get rid of image_style_delete() to find a proper way to implement this
Comment #29
catch#26: 1782244-image-styles-config-entity-26.patch queued for re-testing.
Comment #30
catchGreat to see this one ready. Looks like we'll need a change notice since this removes the _alter() hook and other things. Committed/pushed to 8.x.
Comment #31
xjmWe should additionally document the conversion on http://drupal.org/node/1818734. I've added this issue there but not updated it.
Comment #32
andypostI've updated all related issues with links to this issue, suppose we could change title and priority
http://drupal.org/node/1818734
http://drupal.org/node/1734556
http://drupal.org/node/1799642
Comment #33
gddhttp://drupal.org/node/1820974
Comment #34
andypostSuppose all places are fixed, also we have a special change notice. heyrocker++
Comment #35
webchickI came across #1821534: Can't delete image effects from an image style when testing #1697256: Create a UI for importing new configuration today. Most likely from this issue, I guess. Can someone take a look?
Comment #36
sunSorry for coming late to the party. Unfortunately, there are a range of major problems in the committed code:
(bumping to major, even though some of the changes are actually critical regressions which should turn this issue into a critical bug, but I don't want to pollute the critical queue)
This is actually not true. Configurables have explicit support for renames, which is even covered by tests.
And after fixing the code and testing this manually, it also works as expected.
This should actually run on update only.
Worse, I fail to see how and from where this hook would be invoked. ConfigStorageController invokes the commonly known entity CRUD hooks only; i.e.:
hook_ENTITY_TYPE_insert()
hook_ENTITY_TYPE_update()
hook_entity_insert()
hook_entity_update()
While this hook is invoked, I doubt it is actually doing something.
In order for this to work, $style->id() would have to be set to the replacement style ID before image_image_style_save() is invoked, so it is actually doing something.
And for all of this to work in the config import process, we actually have to figure out a fair amount of things. Updating/replacing references like Image module is doing for image styles will be quite a common task for all Configurables that can be referenced in other configuration. This gets me back to #1609418: Configuration objects are not unique, and as long as that is blocked on consensus, we will have to introduce a new mechanism for the config import process that is able to record and map "replacement config", tracked by UUIDs. The idea of a manifest file, as proposed in #1697256: Create a UI for importing new configuration, might help us to resolve that problem.
Should call $style->delete().
I wonder why we didn't rename 'name' to 'id' as part of this change?
We should create a follow-up for that.
Normally, we are extending/overriding the entity storage controller for such operations.
This is the reason for why we see the full effect definition in configuration files after updating an image effect.
This patch introduced image_style_uri(), but there is a image_style_url() already, which is very confusing. We should rename the entity URI callback to image_style_entity_uri().
Same problem as Image module's implementation.
---
Attached patch fixes most of the problems. I did not move the code to a new ImageStyleStorageController yet though.
Comment #37
sunCreated two follow-ups:
#1821848: Move image style load/update/delete operations into a new ImageStyleStorageController
#1821854: Convert image effects into plugins
Comment #39
yched CreditAttribution: yched commentedDo we still have a use case for the unique ieid ? AFAIK those were only introduced because of limitations in our former *xml* storage (couldn't handle arrays properly).
They are also very hacky and brittle: a string being a hash of effect name plus its settings - no way we can reliably generate that for any arbitrary collection of settings. Besides, it doesnt ensure uniqueness anyway you could perfectly well have the same effect with the same settings twice in the same style, if the effect is not idempotent ("darken by N%")
Comment #40
andypost@sun this issue is about convertion, all other staff should be done in follow-ups as it was written in comments above.
hook_ENTITY_TYPE_insert() => image_image_style_save() && user_image_style_save() is not it?
hook_ENTITY_TYPE_delete() => image_image_style_delete() is not it?
They are very different things
Addressed in #1821534: Can't delete image effects from an image style
PS: I update summary with all this follow-ups
Comment #40.0
andypostAdded follow-ups
Comment #40.1
andypostUpdated issue summary.
Comment #41
sunOk, sorry, you asked for it. #36 tried to clarify that the committed patch entirely broke Image module's maintenance of image styles in field settings.
The regressions are completely obvious in the follow-up patch:
hook_image_style_save()
no longer exists.Attached patch fixes the test failure.
Filed #1822150: EntityStorageControllerInterface::delete() should accept an array of entities, not IDs as a follow-up for the introduced workaround to fix the failures.
Since this is a critical bug now, we need tests that prevent us from re-introducing the regression again. Essentially:
1) Add an image field, using 'medium' style for image widget form upload preview, and 'large' style for the formatter.
2) Create an entity with an image.
3) Delete the 'medium' style using 'thumbnail' as a replacement.
4) Assert that the image field instance's form widget preview style was updated to 'thumbnail'.
5) Delete the 'large' style using 'thumbnail' as a replacement.
6) Assert that the image field formatter was updated to 'thumbnail'.
Comment #42
tim.plunkettThat certainly makes it hard to follow this patch. Can you at least try to make it reviewable?
Comment #43
sunAlso filed #1822176: Why do we have $entity_info['entity keys']['id'] *and* MyEntity::id() method overrides? as another follow-up, since I was very tempted to remove the ::id() method override from ImageStyle, only to figure out that we have some weird entity abstraction duplication going on there.
re #42:
The only change to image_entity_info() is the renamed entity URI callback function name.
The reason for moving it up is that we generally put the registry-alike info hook implementations at the top of a .module file for easier/quick discovery. When I initially reviewed the new code, I completely missed the hook_entity_info() implementation and almost thought it was forgotten, because it was added to the bottom.
Comment #44
xjmSo we had no test coverage for that hook whatsoever? Yikes.
Comment #45
xjmsun's clear "test recipe" in #41 should make it straightforward to add test coverage for this.
Comment #46
xjm#41: drupal8.image-config.41.patch queued for re-testing.
Comment #48
sunRe-rolled against HEAD.
Comment #49
patrickd CreditAttribution: patrickd commentedTested as per #42
Works good, looks good
Comment #50
webchickIf we're fixing a regression, where are the tests?
Comment #51
gddRemoving novice tags
Comment #52
znerol CreditAttribution: znerol commentedIt occurs to me that
ImageAdminStylesTest::testStyleReplacement
should cover the case outlined in #41. What is missing in that test?Comment #53
znerol CreditAttribution: znerol commentedSuccessfully performed the test sequence outlined in #41 on current 8.x (without this patch). That means either we need another test sequence or the problem was fixed in #1821534: Can't delete image effects from an image style (covered by tests). It also means that objections in #45, #50 are probably invalid.
Comment #54
znerol CreditAttribution: znerol commentedSuccessfully performed the test sequence outlined in #41 on current 8.x with commit 0d073ce #1821534: Can't delete image effects from an image style reverted. That means that I'm sort of lost now. @sun or @xjm could you please point out what exactly needs to be tested for?
Comment #55
andypost@znerol sequence from #41 needs to be implemented as test* to proof that #48 fixes the regression
Comment #56
znerol CreditAttribution: znerol commented@andypost: I understand. But in order to verify that the patch actually fixes the regression, we need a test that fails before applying the patch (i.e. current 8.x) and succeeds after applying the patch. However performing the steps outlined in #41 by hand on a fresh 8.x install (and even after rolling back 0d073ce) does not expose any problems. That means that those steps are not suitable to cover the regression.
Before implementing the test I have to know which sequence of steps will lead to the problem the patch tries to fix.
Comment #57
catch#48: drupal8.image-config.48.patch queued for re-testing.
Comment #59
andypostpatch needs re-roll
Comment #60
tim.plunkett#1292470: Convert user pictures to Image Field made some of it obsolete.
Still needs tests.
Comment #62
tim.plunkett#60: image-styles-1782244-60.patch queued for re-testing.
Comment #63
andypostConfirm #53 Styles are replaced successfully without patch and we have a test for that replacement
Anyway patch looks a good clean-up
Comment #64
webchickNo tests?
Comment #65
gddtestStyleReplacement() has always existed to test style replacement, which was never actually broken despite claims to the contrary (verified in #53 and #63.) Setting back to RTBC.
Comment #66
webchickI just spent like 20 minutes trying to parse what the actual critical problem is here in order to determine what regression we're fixing, and it seems like there is none.
- There are steps to reproduce a bug in #41. However, those steps are refuted by later comments (#53 and #56) which are able to do those tasks successfully.
- The patch itself doesn't really contain much in the way of functional changes aside from removing image_style_delete() in favour of $style->delete() and changing hook_image_style_save() to hook_image_style_update(). One would think that if that were fixing some kind of critical bug, the existing tests in ImageAdminStylesTest.php would've been raising a stink about it, because they seem pretty thorough.
So as far as I can tell, this is just a straight-forward follow-up to improve some things, by better leveraging more of the Config Entity API and making the scope of the hook more direct. OK, great. But let's done down the drama-meter, OK? :)
Needs a re-roll.
Comment #67
webchickproject_issue--
Comment #68
gddHere is a reroll to HEAD. One slightly notable change: hook_config_import_delete() was removed by #1806178: Remove code duplication for hook_config_import_*() implementations of config entities, and the @todo related to it in image.api.php is also resolved from that issue, so the two related hunks are just removed.
Other than that its a straight reroll. Should go right back to RTBC if the bot passes.
Comment #69
gddComment #70
sunComment #71
webchickCommitted and pushed to 8.x. Thanks!
Comment #72
andypostMajor follow-up #1821848-17: Move image style load/update/delete operations into a new ImageStyleStorageController
ImageStyleStorageController::importDelete()
uses removed functionimage_style_delete()