Problem/Motivation
There's an issue to support adding third party settings to sections: #2942661: Sections should have third-party settings, but it would be great to also support third party settings for individual components (blocks) within a section.
For example, modules like Block Class, Field Formatter Class, Panopoly or Fences Block use third party settings on block config entities to allow the user to add arbitrary CSS classes to a block. It seems that the only way to do this with a Layout Builder block is to modify the settings form for the individual block plugin you want to modify and store the configuration along with the other configuration for that block.
Proposed resolution
SectionComponent should implement ThirdPartySettingsInterface
Remaining tasks
N/A
User interface changes
N/A
API changes
Because there was an existing similar approach ($additional)), deprecations are added with full BC
Data model changes
Data model addition
Release notes snippet
N/A
Known issues
Early version of this patch included a legacyAdditionalModuleKey class property on SectionComponents. If people used this patch and then upgraded to the latest, you will get a lot of errors like the following:
Deprecated function: Creation of dynamic property Drupal\layout_builder\SectionComponent::$legacyAdditionalModuleKey is deprecated in Drupal\Component\Serialization\PhpSerialize::decode() (line 21 of core/lib/Drupal/Component/Serialization/PhpSerialize.php).
This is because the entire component tree is serialized into the database, and when unserializing that property no longer exists and throws the error.
Resolving this is not very easy due to the API surrounding Sections and Components. A gist is available which contains a batched post update hook to scan all Node revisions for this key and fix the issue.
https://gist.github.com/acbramley/53578b18b27466f1b508aedb12907b5e
The first file is a helper utility class that can be used for any sort of generic entity data migration. The post update hook uses this utility to replace SectionComponents with this legacy property.
| Comment | File | Size | Author |
|---|---|---|---|
| #295 | 3015152-11.3.2-no_tests.patch | 16.95 KB | mkdok |
| #236 | legacyAdditionalModuleKey.png | 214.34 KB | flyke |
| #246 | sectioncomponents-error.png | 310.5 KB | flyke |
| #249 | 3015152-249.patch | 41.69 KB | stomusic |
Issue fork drupal-3015152
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3015152-support-third-party-11.x
changes, plain diff MR !5053
- 3015152-support_third_party_settings_for_components_within_a_section-10.x
changes, plain diff MR !14167
- 11.x
compare
- 10.6.x
compare
- 10.5.x
compare
- 10.4.x
compare
- 10.3.x
compare
- 3015152-support-third-party-10.3.x-php8.2
changes, plain diff MR !8724
- 3015152-support-third-party-10.3.x
changes, plain diff MR !8474
- 3015152-support-third-party-10.2.x
changes, plain diff MR !6118
- 10.2.x
compare
- drupal-3015152
compare
- drupal-3015152-3015152-support-third-party-11.x
compare
- 3015152-support-third-party-9.4.x
changes, plain diff MR !2654
- 3015152-support-third-party
changes, plain diff MR !1506
Comments
Comment #2
tim.plunkettLet's do this in #2942661: Sections should have third-party settings after all
Comment #3
tedbowSplitting back out from #2942661: Sections should have third-party settings because adding third party settings to Sections is more complicated because of changes the constructor and BC
Comment #4
jian he commentedOnly have functional code, does not have testing code yet. Just want to make things working. I am idiot for writing testing code.
Comment #5
jian he commentedFix failed testing.
Comment #8
bkosborneThis patch adds TPS to sections, but sections already have the $additional param. We need to decide: Is there a point of having both? If not, perhaps $additional should be removed and an upgrade path written.
Comment #9
tim.plunkettI don't think there is any value to additional if we can have TPS.
The problem is how to provide BC in the meantime.
Comment #10
tim.plunkettComment #11
jwilson3Field Formatter Class module also suffers from an issue where the third party settings are somehow stripped by Layout Builder when it switches to the internal '_custom' view mode for field blocks.
The issue I'm currently battling on in contrib:
#3046372: Classes not being applied with Layout Builder
Edit: I just realized the patches on this are for SectionComponent.php class, which I assume is what "blocks" in the UI are?
Comment #12
jwilson3Cross-post but with the patch from #5 applied to 8.7.1, I'm still unable to access the third_party_settings from hook_preprocess_field function for a field rendered by Layout Builder for anonymous users.
I've tried loading settings both the current way that the field_formatter_class module is written:
But the documentation for EntityViewDisplay::collectRenderDisplay make it sound like this way is going to be deprecated and points to using entity_view_display() which ALSO has a deprecation warning and suggests using:
Neither of these ways above produce the correct config even with the patch applied. Layout Builder's '_custom' view mode seems to still be stripping out third party settings.
In fact, Drupal 8.8.x introduced EntityDisplayRepositoryInterface::getViewDisplay() as the way to do this, but since I'm working on 8.7.x I cannot use that yet.
Its late in the week, so I'm probably doing something wrong.
Comment #13
jwineichen commentedPatch from #5 is working with Block Class with additional patch on that module (https://www.drupal.org/project/block_class/issues/2998114).
Comment #14
murzI confirm too, that patch works well together with https://www.drupal.org/project/block_class/issues/2998114#comment-13137003 for add classes to layout blocks in Drupal 8.7 core.
Comment #15
altrugon commentedJust tested and indeed works fine. Changing ticket status.
Comment #16
segovia94 commentedThis is a reroll of #5 for 8.8.x.
Comment #19
segovia94 commentedUmami uses layout builder for the Full recipe view mode. The config test for it was failing since this patch adds in extra config for third party settings. This new patch hopefully fixes that.
Comment #20
segovia94 commentedComment #21
jhedstromThis is looking good. I like that the additional property is properly deprecated :)
One note on the test modifications though:
I don't think we can just add this to the update test fixture. Rather, we need an update hook with this patch that would set this property in existing configs, and then a test to ensure that update path properly adds the property. This test could use the same fixtures as the existing update tests the module has I think. See
ExtraFieldUpdatePathTest, or the test modified in this patch for examples.Comment #22
aleksipRemoved
third_party_settingsfromLayoutBuilderEnableUpdatePathTest.Comment #23
jhedstromSorry, I quoted the wrong code in #22. It actually needs to be removed from
core/modules/layout_builder/tests/fixtures/update/layout-builder-enable.php, which is a test fixture that mimics an existing installation. It should be added back to theLayoutBuilderEnableUpdatePathTest, but for that to then pass, we'll need an update hook that addsthird_party_settingsto existing installations/configs.Comment #24
aleksip@jhedstrom Ah, ok, no worries, my patch was meant to be just a test before more work on this during DrupalCon contribution day, but in the end I couldn't get tests working locally, so had to give up.
I'm still fighting with local tests, but meanwhile here is a reroll of the earlier #19 patch.
I'm curious, how is this issue different from #2942661: Sections should have third-party settings regarding the implementation of tests? Shouldn't this issue mimic that one, or am I missing something?
Comment #25
aleksipComment #26
joey-santiago commentedRe-rolled the patch against 8.8.0. Hope this is fine :)
Comment #27
mark.labrecqueTested the re-roll and it looks good. Adding my RBTC to this one. Let's get it committed upstream so we can fix it at the specific module levels :)
Comment #28
mark.labrecqueComment #29
chris burge commentedThis is going to need a change record: See https://www.drupal.org/node/3035096 as an example.
Comment #30
mark.labrecqueComment #31
mark.labrecqueAdded a draft change record for this patch. Please review it here and add more detail if it is needed.
Comment #32
mark.labrecqueComment #33
alexpottI'm not sure this is correct. I think that the module that provides the new settings should be able to add a schema here.
Also it look like we're missing dependencies as well. So when you uninstall a module that allows information to be stored here the information should be removed as it is no longer relevant.
Comment #34
chris burge commentedWhat about the following?
This works in my testing with the following contrib schema:
For the sake of consistency, I tried unsuccessfully to adapt the third-party settings type for sections,
'[%parent.%parent.%type].third_party.[%key]'. I ended up with'[%parent.%parent.%parent.%type].third_party_settings.layout_builder.sections.[%parent.%parent.%parent.%key].components.[%parent.uuid].third_party_settings.[%key]'(and also tried countless various thereof).It also looks like we'll need post-update code:
Comment #35
anybodyThank you very much @Chris Burge, @alexpott and the others! I just ran into a situation in "fences_blocks" where we have the same requirement (#3117170). Sadly I'm not experienced enough with the schema topic in #34 to help to answer this.
I'm willing to help writing tests to get this done, if someone could teach me what to test and perhaps show a first example so I can do the time consuming further test implementations perhaps?
Comment #36
morbus iffThe current patch in #26 is applying cleanly in 8.9.0.
Comment #37
larowlanNew features will only go into 9.1.x now.
Comment #38
amjad1233Comment #39
ravi.shankar commentedComment #40
larowlanThis is a feature, we're hoping to keep the Bug Smash tag just for Bugs. But feel free to help move this along!
Comment #41
ravi.shankar commentedAdded reroll of patch #26 for Drupal 9.1.x.
Still needs work for #33.
Comment #42
larowlanLooking at how we generally do third-party settings for config-objects - core's entity schema for config_entity type has this
E.g. looking at how contact_storage provides schema for the third-party settings it adds to contact forms, it has this in its schema
So I think we need to do similar but also
Comment #43
chris burge commentedThe 'type' value in the schema is the major hurdle at this point IMHO. (As I commented in #34, I have no idea what the 'type' value should be for the schema. I tried a bunch of stuff that didn't work.)
It also looks like we'll need post-update code:
Agreed we need to add test coverage. (Tag added to issue).
The only test-related code in the patch is below:
Comment #44
geek-merlin> The 'type' value in the schema is the major hurdle at this point
It must be a definition that allows the third parties to actually define the schema. Look how it's done in other places. So here it is:
(Note that the "[%parent.%parent.%type]" here resolves to "layout_builder.component". (We could have written that.)
So if 'mymodule' adds some TPS, it will define layout_builder.component.third_party.mymodule.
HTH!
Comment #45
chris burge commented@geek-merlin - Thanks for your comment. That's 100% correct. When I was testing, I used patch #67 from Block Class #2998114: Integration with Drupal core's new Layout Builder. Upon reviewing your comment, I discovered that the necessary schema was missing from that patch. When I account for the missing schema, everything works perfectly. SO - no schema issues on this core issue.
That just leaves the post-update code and test coverage. Re test coverage, I'd look to #2942661: Sections should have third-party settings for guidance.
Comment #46
geek-merlinI think this line has to be changed to:
Comment #47
adityasingh commentedComment #48
adityasingh commentedUpdated patch as per the changes suggested in #46, please review.
Comment #49
adityasingh commentedComment #51
geek-merlinNow that we have a schema, the test fails as it should.
This adds a TPS for which no schema exists.
The above needs a schema like
Comment #52
chris burge commented+1 for #51, but that only addresses half of the test failure. (The schema needs added in layout_builder_defaults_test.schema.yml btw.)
You'll still get the following failure:
It's the result of how we're dealing with the
$additionalparameter in the SectionComponent constructor:When we pass a value as the
$additionalparameter, it gets added as a TPS with '_layout_builder' as the key.My vote is that don't do this. We have no idea what's in
$additional. If anyone is using$additional, then it's up to them to figure how to migrate data to TPS. That's the position we've taken with the Layout Builder Component Attributes module.Comment #53
chris burge commentedWe also need to add a deprecation tag to the
$additionalproperty:Comment #54
geek-merlinI did not research how we want to handle BC of $additional, bu i suppose we have to keep it.
So let's do:
and remove that chunk instead:
Comment #55
chris burge commentedIt's probably best that we leave the schema alone for 'additional'. I think the bigger issue is how the patch attempts to merge 'additional' into TPS with the '_layout_builder' provider key.
Let's assume we have a module that is currently using the 'additional' property. Currently, it writes its data using
SectionComponent->set(), and it reads its data withSectionComponent->get(). Assume that there is data in 'additional' when we apply patch #48.When we apply the patch, the module will no longer be able to retrieve its data. Before, the
get()method would look in$this->additionalfor a given property. Now it will look in TPS using the '_layout_builder' provider key. It won't find any data because the data is still in 'additional' and we didn't perform any type of data migration from 'additional' to TPS. Patch #48 would break existing modules that are using 'additional'.I think the better route to take would be to deprecate 'additional' and otherwise leave it alone. This means removing the
$legacyAdditionalModuleKeyprivate property and all of its uses.Comment #56
geek-merlinI can follow the reasoning in #55 and it makes sense to me.
Comment #57
chris burge commentedI'm going to re-roll #48 with the code changes discussed since then and also add test coverage based on section third-party settings tests.
Comment #58
chris burge commentedUpdated patch is attached, along with an interdiff. Everything since #48 should be incorporated.
I updated the deprecation notice because Coder wanted a particular syntax:
Coder error:
Code change:
Comment #59
tim.plunkettI think I'm okay with the removal of the attempted additional->TPS code. Unless that is needed to fix the constructor, then I'd consider it...
Is there a good way to swap the order here so that eventually $additional can be dropped?
Other times it's been done via instanceof checks, but that's not possible here.
This should be wrapped in a !empty and get a trigger_error too
This is never reused outside the method.
I'm all for fun test content, but can you pick something that doesn't need escaping? Makes every line it's on harder to read.
That's some excessive wrapping. Could probably just be a one-liner.
Please add explanatory array keys for the data providers, explaining what each is testing.
Comment #60
chris burge commentedIt's not needed to fix the constructor. The reason for removing the attempted additional->TPS code is because that code will break modules currently using
$additional.As long as we add
$third_party_settingsto the end of the constructor signature, we don't need a BC layer. We're designating$additionalas deprecated. When D10 is released, the constructor signature will change (right?). Won't this be handled the same as The signature of the constructor of Drupal\file\FileUsage\DatabaseFileUsageBackend has changed. but without the BC piece?D9 constructor:
D10 constructor:
Do you mean something like?
Comment #61
tim.plunkett(Adopting numbering based on my comment)
1)
There absolutely was a BC layer for DatabaseFileUsageConstructor. Compare the following:
https://git.drupalcode.org/project/drupal/-/blob/8.7.x/core/modules/file...
https://git.drupalcode.org/project/drupal/-/blob/8.8.x/core/modules/file...
https://git.drupalcode.org/project/drupal/-/blob/9.0.x/core/modules/file...
The second one (8.8.x) is what I was referring to when I said "Other times it's been done via instanceof checks" in #59.1
Whatever we do, the calling code in 9.1 has to be able to be the same as it is in both 9.0 and 10.0
$additional must be supported for all of 9.x, but there must be a way to write code that is valid for both.
What I wish we had done was go the route of a protected/private constructor, and used static factory methods.
Adding a ::create() method might be the only option to achieve this, but I'm open to ideas.
6)
Skip the "verify", but yes. Consider those keys to be like the one-liner if they were individual test methods (but not as full-sentence-y)
Comment #62
chris burge commentedI understand the constructor issue now.
I don't have a better solution. Is there an example out there in core to use for a reference for this use case?
Comment #63
tim.plunkett\Drupal\update\ModuleVersion
\Drupal\update\ProjectSecurityData
\Drupal\update\ProjectSecurityRequirement
That's a trio recently added to core. Note the private constructors and the static create* methods.
Comment #64
chris burge commentedIf we wanted to switch to a private constructor, would that transition look something like this?
::create()method is added; instantiatingSectionComponentobject directly is supported but deprecated::create()method becomes the only way to instantiate aSectionComponentobjectA module that is compatible with both D9 and D10 would use the
::create()method.Comment #65
tim.plunkettYep that's exactly what I was thinking, thanks for writing it out so clearly
The tricky part is how to trigger_error in 9.1 when the constructor is called directly. Idk the best way to handle that, either have ::create() set a private property to TRUE and then check that? Or inspect the backtrace 🤢
Comment #66
chris burge commentedI'll roll code using a create method with a private property into the next patch. It seems like the least bad option.
If we wanted to stick with a public constructor, I believe it'd take us until D11 to completely wrap that up:
Comment #67
chris burge commentedUpdated patch, along with interdiff, is attached. All changes from #59 and #61 have been made.
I ended up going the backtrace route. The
SectionComponentobject needs to exist before setting the private property. At the point I can set the private property, it's too late to trigger a deprecation notice (in__construct()) because the object has already been created.[Note: We don't have a follow-up issue, so I'm using https://www.drupal.org/node/123456 for now in @todo comments.]
Comment #68
chris burge commentedRe the test results for #67, we're seeing a bunch of deprecation notices because I didn't replace
new SectionComponentwithSectionComponent::createoutside of the existing work of this issue. I figured I see what feedback there is on the current approach first.Comment #69
geek-merlinLooks good!
I'm a bit concerned though about the performance
and memoryfootprint of this, given we may have lots of sections on a page.The only alternative i can see is yet another temporary constructor argument named something like
$isCalledViaCreateMethodInD9...Comment #70
chris burge commented@geek-merlin - I share your concern. I was trying not to introduce another constructor argument; however, it may be the lesser evil. We'll be checking how the
SectionComponentobject was created for each component for a given Layout Builder-enabled entity.Comment #71
chris burge commentedComment #72
chris burge commentedAdding related issue: #3159712: SectionComponent should provide an unset() method. Modules using
$additionalcan't clean up after themselves without anunset()method provided bySectionComponent. This will be needed once$additionalis deprecated by this issue.Comment #73
segovia94 commentedI tested the #67 patch with two modules. The first is Block Style Plugins which utilizes the new Third Party Settings and also Layout Builder Styles which utilizes the deprecated "additional" key. Both worked fine and both passed their tests on my local.
I would RTBC this, but I'm not sure if #68 needs to be addressed first.
Comment #74
chris burge commented@segovia94 - Thanks for testing and posting your findings. I should have an updated patch the takes care of the remaining tasks in the next 1-2 days.
Per #3159712: SectionComponent should provide an unset() method, we're not going to be adding an
unset()method. This is already possible using a combination ofget()andset(). This means the tools are there for an upgrade path from$additionalto third party settings. Once$additionalis removed, we'll no longer have a need for theget()andset()methods, so they can be deprecated, too.Remaining tasks:
new SectionComponentwithSectionComponent::createget()andset()per #3159712: SectionComponent should provide an unset() methodComment #75
chris burge commentedUpdated patch is attached.
A D10 follow-up issue has been created: #3160644: Remove deprecations and update constructor for \Drupal\layout_builder\SectionComponent.
At this point, everything is completed, except for updating the change record. I think we should wait for that step until the subsystem maintainers have weighed in.
Comment #76
tim.plunkettConsider this sign-off as the relevant subsystem maintainer.
Nit: all of these leading parens were because of calling a method on the object created by
newand that is no longer relevant and they should be removed.Regardless of the fact that this could be used even after it is private, let's switch this to explicitly use ::create() as well.
One thing that is missing are explicit tests for each of the @trigger_error calls
Comment #77
chris burge commentedUpdated patch attached with the following change:
:::create()method cannot accept the$additionalparameter. Existing code that calls::fromArray()and passes an 'additional' value would not execute as expected because::create()cannot provide that data to the constructor.Comment #79
chris burge commentedRerolled patch addresses new committed code that's causing deprecation notices. It also adds a comment to address 76.2.
Comment #80
chris burge commentedPer #3161300: Improve test coverage of \Drupal\Tests\layout_builder\Unit\SectionTest::testUnsetThirdPartySetting(),
::testUnsetThirdPartySetting()needs updated to run assertions on non-existing providers and non-existing keys. It also needs to use a data provider for consistency with other tests in its class.Comment #81
chris burge commentedUpdated patch attached.
Comment #82
chris burge commentedUpdated patch with typo fix.
Comment #83
neslee canil pinto#82 worked for me along with one of my modules to support third party settings. Moving it to RTBC
Comment #85
chris burge commentedTest failure was an intermittent and unrelated failure of
Drupal\Tests\ckeditor\FunctionalJavascript\CKEditorIntegrationTest. Setting back to RTBC.Comment #86
akalam commented#82 does not apply on Drupal 9.0.x because 9.0 has no layout_builder_element_test module. Removing that part on patch makes it apply. Uploading the patch adapted to Drupal 9.0.x
Comment #87
chris burge commentedRe #86, this issue is targeted for 9.1.x, not 9.0.x. New features cannot go in 9.0.x.
Comment #89
geek-merlinSo current RTBC patch is #82.
Comment #90
tim.plunkettReuploading the actual patch from #82. Please don't queue patches against the non-development branch, it just derails the issue by taking it out of the RTBC queue.
Comment #91
larowlanSo this is called heavily on deserializing from stored values in the DB right?
Do we have a plan for removing saved values in the additional key from stored overrides?
When we get to D10, will those just be silently ignored?
Other than that, I've got no other questions with this patch, and have been running it in production for some time.
Comment #92
chris burge commentedI'm not sure I follow. That code is part of the
fromArray()method, which creates aSectionComponentobject from an array.When I was working on this patch, it was with the belief that anyone using 'additional' would be responsible for their own clean up.
I'm the maintainer of the Layout Builder Component Attributes module. All data stored in 'additional' is removed on uninstall: layout_builder_component_attributes.install.
That seems reasonable.
Comment #93
tim.plunkettNote that
\Drupal\layout_builder\Section::fromArray()has a similar += construct to the one added here.This is called via
\Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplayStorage::mapFromStorageRecords()when reconstructing an entity view display out of the DB. Interestingly enough, we don't have any custom code that runs for the field-based values.\Drupal\layout_builder\Plugin\Field\FieldType\LayoutSectionItem::schema()specifies'serialize' => TRUE, and that's enough. The only other relevant call is\Drupal\layout_builder\Field\LayoutSectionItemList::preSave(), which is a fromArray wrapped around a toArray call.As far as cleaning up, I'm not sure we need to do more. I added a note to the D10 follow-up about removing the schema definition, but it should stay.
Comment #94
alexpottI think maybe we can do a little bit more to cleanup.
We can deprecate this now. See https://www.drupal.org/node/3129881
This seems icky but pragmatic and will help custom and contrib update. Nice.
I think we should be removing this when it is empty so it doesn't end up in configuration unnecessarily. That way we'll produce config valid for Drupal 10 if
additionalis not used.Additionally we need an update path to remove this when it is empty. i.e. we should use the ConfigEntityUpdater to re-save them as this should remove the empty ones.
Comment #96
joey-santiago commentedWe were using a patch from this thread that disappeared completely:
https://www.drupal.org/files/issues/2020-11-20/3015152-tps-96.patch
... is it possible to get it back? :)
thanks
Comment #97
tim.plunkettYour comment is #96. And the patch you're looking for is numbered 96...
And the file path is November 20th, but no one here commented then.
So I'm confused.
If you look at the Files section, you can show all files and look through the ones there? But yeah no idea
Comment #98
hkirsman commentedWe added it to your project at 20'th of November. 30 days later it was deleted. Sounds like Drupal files cleanup. The patch is tied to comment and if you'd forget to actually comment then it gets deleted?
Comment #99
szeidler commentedOrphaned files that have been uploaded, but are not related to any entity (e.g. the comment was not saved) or not marked as permenant in another way, will be automatically cleaned up and removed.
That behavior you can also experience in every Drupal installation.
Comment #100
fabianx commentedNot wanting to derail, but should this and the following functions not really be in a trait?
Given it it the exact same code as in:
https://www.drupal.org/project/drupal/issues/2942661
etc.
---
Overall +1 to the issue though
Comment #101
fabianx commentedhttps://www.drupal.org/project/drupal/issues/3158694
Comment #102
andypostuuid and region needs string types declared
region is the string type (not array)
Comment #103
mxh commentedAddressing #102 and #94, but still missing update path suggested in #94. Hope I understood the remarks correctly.
Agree with #100 but suggest to make follow-up issue for addressing it once the trait is in.
Comment #104
tim.plunkettAs much as I appreciate the Office Space / TPS references, we have cspell now and the following words aren't in the dictionary:
Initech
Lumbergh
Waddams
Chotchkies
That's why it's failing tests.
Comment #105
anmolgoyal74 commentedAdded words to the dictionary.txt file.
Comment #106
anmolgoyal74 commentedComment #108
mxh commentedLooks like the added
deprecatedkey is flooding those deprecation notices within the CI.Besides that, unfortunately I forgot to add the link ("See https://...") into that deprecation message, this needs to be added (sorry :/).
I have no clue why the diff assertion for
core.entity_view_display.node.article.fullfails inDemo_umami.Drupal\Tests\demo_umami\Functional\DemoUmamiProfileTest, it shouldn't have been touched within this patch? I added thethird_party_settings: { }tolayout_builder_defaults_test/config/install/core.entity_view_display.entity_test.bundle_with_extra_fields.default.ymlthough.Comment #109
mxh commentedJust want to get rid of the flooded deprecation notices first, can re-add it properly later if really needed. Just want to see what else might be wrong.
Comment #110
mxh commentedComment #111
mxh commentedReplaced deprectated
@expectedDeprecationannotation (the inception of deprecations...).Comment #114
mxh commentedI guess the removal of the
additional: { }entries in the config installation files need to be moved to an extra D10 port, because some tests check for config diffs. Reverted the removals in this patch now. Not sure how to handle thedeprecatedkey in the config schema without breaking all the tests (see test results from #105). Alternatively, the config schema could get a@todocomment in the D9 patch.Comment #115
tim.plunkettSorry for not being clear in #104: I meant "remove those strings" not "add them to the dictionary". But I'll leave that to a committer to decide about pushing back on.
I think the failure in #114 is because #3108503: Enable layout builder by default on all content types in Umami was only committed to 9.2, and now there's an additional config file to fix:
core.entity_view_display.node.article.fullComment #116
mxh commentedThanks for the hint, trying to create the 9.2.x port of #114 (which stands for 9.1.x) with this patch now.
It would be helpful to have a more clear policy on how to decide what should be added into that dictionary and when it should be changed / replaced by existing words instead.
Comment #117
mxh commentedAt the current state of this patch, there is no form handling regards TPS inlcuded (see
ConfigureBlockFormBase::submitFormand its::validateForm).On entity forms, TPS can be included and may be saved without a custom submit handler (I guess due to "magical" entity build processing within
EntityForm). Also no custom validation callback is required e.g. when using a simple select widget. ShouldSectionComponentinstances also have a way of auto-including TPS form values?Another thing that's kind of weird is that
SectionComponentimplementsThirdPartySettingsInterfacefrom theDrupal\Core\Config\Entitynamespace, butSectionComponentis not part of the entity system.Comment #118
anybodyComment #119
anybodyHi @mxh re:#117 the patch in #116 works well for us so far and tests are green which might be RTBC+1 but from your points in #117 I guess we'd have to set this back to "Needs work" as you'd expect the "magic" to happen consistently for all areas?
What steps do you think have to be done and what decisions to be made by whom?
Comment #120
mxh commentedHi @Anybody, I'd say a core maintainer needs to decide whether that concern stated in #117 should be addressed or not. Just noticed that the
Sectionclass already includes TPS officially in core, so it's probably not a problem to also include TPS forSectionComponent.Comment #122
anybodyThank you @mxh, so I will change status to Needs work. Do we have to add any tags for that decision?
Comment #123
tim.plunkettThirdPartySettingsInterfaceis used in 4 places in core, and only one of those is within the Entity system. It *is* definitely a misleading namespace, but I think it's reuse is more valuable.Comment #124
segovia94 commentedRe-roll against 9.3.x
Comment #128
feng-shui commentedRe-roll against 9.3.0 (applies against 9.4.x and 10.0.x), I'm not sure how to roll an inter-diff on this since the patch in 124 doesn't apply against 9.3.0 anymore. I'm pretty sure that this is a correct re-roll, but would be happy to have someone else take a look (and get an inter diff working) to confirm.
Comment #129
anybody@segovia94, @hswong3i and @Feng-Shui thank you for rerolling.
@tim.plunkett you set this back to "Needs review" in #123 - can we see this as reply to #120? If yes, who should have a look at this next? The missing integration is blocking several contrib modules from layout builder support and forces using workarounds, as the list of related issues shows.
Hope it's okay to bring this back to the attention for that reason.
Comment #130
thiagomoraesp commentedPatch from #124 failed to apply on my 9.3.x, anyone has any other patch that works on 9.3.x?
Comment #131
feng-shui commented@thiagomoraesp #128 is a reroll against 9.3, did you try it?
Comment #132
thiagomoraesp commented@Feng-Shui, the #128 didn't work too.
[EDIT]
Sorry, my mistake, it is passing on my 9.3.x, i was applying the same patch 2 times.
Comment #133
anybodyAdded further contrib module not working correctly in LB due to this.@tim.plunkett could you perhaps have a look at #129 => #120 (if you find the time)? I guess this needs core maintainer feedback about how to proceed?
@thiagomoraesp could you please clarify in #132 if it works now after correcting your mistake?
Comment #134
anybodyComment #135
anybodyComment #136
heddnI think the change record could be more specific to how to accommodate third party on component blocks themself. Even if it is a copy/paste and rename of variables, it isn't clear where I need to adjust my custom code that let's me add CSS classes on any LB block.
Comment #137
heddnThere's also still quite a few references to
$additionalin the code base. And we should open a follow-up to component_library (if it doesn't exist), to swap out$additionalfor tps. Actually, this wouldn't need to be a follow-up. It could happen now and as we'll want to do a instanceof check on the SectionComponent object to see if it implements ThirdPartySettingsInterface and swap out additional for tps when constructing the section component.Comment #138
heddnI not fully convinced this will help with BC. We can deprecate on
__constructif anything is passed to$additional. Then entirely remove$additionalin Drupal 11. In PHP 8.1 we have named parameters and we can handle deprecation a lot easier then. And this is likely to be deprecated in Drupal 10 and sunset in Drupal 11 at this point. Can we evaluate another approach for deprecation here?Comment #139
heddnThere might be some test failures here, but this converts back to the more traditional
new SectionComponent()approach and updates things for removal in Drupal 11. There might be a few places I missed in cleaning up. Testbot will help here. But the revert did show a lack in fully testing TPS in thatDefaultsSectionStorageTest::providerTestAccesswas formatted incorrectly for the config schema validation.I also updated the CR, so cleaning up tags.
Comment #140
heddnAnother benefit to removing the
::create()logic is this is a very reviewable issue now. Much smaller footprint. And the amount of BC adjustments needed should be much smaller for folks who weren't passing around TPS anyway. In some ways, that make it an easier adjustment for most people (no change for simple use cases). Rather than adding the new constructor mechanism and everyone would need to change their constructor. Some minor notes below from a formal review of the patch.Oops, I missed a version adjustment here.
This version should also get updated.
return $this->thirdPartySettings[$provider][$key] ?? $default;
return $this->thirdPartySettings[$provider] ?? [];
Comment #142
heddnLast test failures were random js test failures. Otherwise, it was green. Here we fix a few self review nits (mentioned in #141).
Comment #143
larowlanThis looks good, like the pivot away from ::create
shouldn't this load and resave any view display that is LB enabled so the new third_party_settings keys are added?
I think we can still target 10.0.0 for removals
Should we make this private, and implement __get and trigger a deprecation if someone accesses it?
We will need methods for getConfiguration and getWeight then, as there's no way to get them without using get - if we intend to deprecate the whole function.
If that's not the intention then we should remove this annotation as IDEs will mark the whole method as deprecated
I think we can safely deprecate any calls to this method as there is setConfiguration and setWeight already, so there's no reason to use it if additional is deprecated
This will go into 10.0.x first, so we probably want another branch/patch where that is already gone
;-)
let's add a :void while we're here (and the other methods)
I think we still expect a return-type hint and @return docs here (same for other methods)
micronit: can return early and avoid else
Comment #144
heddnThanks for the feedback in #143.
143.1: done
143.2: done, but see my comments for 143.6.
143.3: I'm mainly worried about serialization and private properties biting us. See #3110266: Support serialization of private properties. I don't think there is a strong benefit to do this.
143:4: addressed. there were already getters. Just needed to make configuration's public.
143.5: fixed
143.6: before we do that, I recently had to switch everything in #3267870: Order image mappings by breakpoint ID and numeric multiplier to deprecated in 9.4 and removal in 11.0.0. Are we sure we want to remove already in Drupal 10.0.0?
143.7: nice
143.8: done
143.9: fixed
143.10: fixed
Comment #145
heddnComment #147
heddnBehold, test coverage of the update path and a few other fixes.
Comment #148
larowlanThis is looking great, nice to see it coming together
we don't need this anymore, now we have an actual post update hook, the caches will be cleared
Should we remove this and use something like \Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait to trigger a deprecation on access to it? Or are we safe to assume that SectionComponent shouldn't be extended. Might be a question for @tim.plunkett
Comment #149
tim.plunkettSectionComponent has no interface, it is a value object. Had usage of
finaland/orprivatebeen permitted at the time, we would have used that (final for the class, private for the property).It is typehinted directly in several places, and is always created via
new, with no opportunity to be subclassed.So I think this is fine, and the deprecation trait would be overkill.
Happy to RTBC after the first point of #148 is addressed
Comment #150
heddnStandardized on Drupal 11 deprecation removal. See #144 and 143.6. Happy to flip that to Drupal 10 if I'm misreading things.
I also addressed #148.1
Comment #151
tim bozeman commentedFantastic!
Comment #154
heddnComment #156
chris burge commentedRe-queued 3015152-150.patch to check if #155 is an intermittent FunctionalJavascript failure:
Comment #157
heddnComment #158
abarrioAny news on this?
It would be ok to have it on next release in order to extend functionalities.
Comment #159
ravi.shankar commentedAdded reroll of patch #150 for Drupal 10.0.x, as this will go to Drupal 10 also.
Comment #161
anybodyComment #163
anybody#150 and #159 both fail with the following strange error:
Comment #164
ravi.shankar commentedAdded reroll of patch #150 on Drupal 9.5.x. as It's not getting applied.
Comment #165
ravi.shankar commentedAdded reroll of patch #150 on Drupal 9.5.x. as It's not getting applied.
Please ignore patch #164, there was an extra file that got added by mistake.
Comment #166
anybody@ravi.shankar can we get an interdiff? If this is just a reroll with no code content changes, we can set this back to RTBC as of #157 (@heddn)
Comment #167
ravi.shankar commentedAdded reroll diff of patch #150 and #165.
Comment #168
anybodyThanks, so I'm setting this RTBC again. Patch for Drupal 10 would also be useful again. Hopefully this will be committed soon so we don't need further rerolls :)
Thanks a lot @ravi.shankar!!
Comment #170
anybodyComment #172
hswong3i commentedComment #173
hswong3i commentedComment #174
hswong3i commentedComment #175
grevil commented@hswong3i could you tell us the reason you created a separate identically named Merge Request with over 1000 changes, changed both MRs target branch to 9.4.x and created patches which do not apply to 9.4.x?
Comment #176
anybodyRTBC is still for #165.
Comment #177
anybody@ravi.shankar sorry, reading the patch one more time I saw these lines:
This is just a textual issue, but should be drupal:9.5.0?
Or should this be updated to the matching version right before commit?
Leaving this RTBC for maintainers to decide, would be duplicate work if we have to update the versions again and again. So I'd vote to update the string right before commit.
If you decide to update it now, please provide an interdiff. Thanks! :)
Comment #178
anybodyComment #179
quietone commentedOnly module/theme deprecations are allowed in Drupal 9.5 so this will need to move to Drupal 10.1. Updating version and adding tag for a re-roll.
As pointed out in #175, the work done by @hswong3i has no explanation and is not helping to resolve this issue. Therefor, credit has been removed per How is credit granted for Drupal core issues.
Comment #180
vsujeetkumar commentedRe-roll patch created for 10.1.x from #165, Please have a look.
Comment #182
Ankit.Gupta commentedReroll the patch #180 with Drupal 10.1.x
Comment #183
amarlataFixed coding standard.
Comment #184
Ratan Priya commentedFixed failed custom command for patch #183.
Comment #186
WebbehIt would be incredibly helpful to have interdiffs for #183 to understand what "coding standards" have changed between the re-roll. As a friendly reminder, when posting patches, interdiffs help provide clarity on changes between patches, which is incredibly helpful on a long issue with a rather large patch, like this issue.
Placing this for Needs Review based on the fixed (??) reroll in #184, so we can return to RTBC (per requests in #176 and #179).
Comment #187
larowlanLooked at this in detail again.
The only question I have left is what happens for entity view display config in e.g. install profiles that are in profiles/some_profile/config/install
Those won't have the third_party_settings option. I don't think it will matter because our constructor has a default value of [] so the key will be set next time they're saved. So it would be good to validate, possibly via a test, that importing those items doesn't trigger any errors.
Comment #188
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #189
amjad1233Patch re-rolled for Drupal 9.5.3
Comment #190
szeidler commentedSomething went wrong in some of the recent of the patches for 9.x. The patch adds
usefor classes that are declared already since a few Drupal core releases.Comment #191
amjad1233Another stab at re-roll...
Against 9.5.x
Comment #192
heddnAgainst 10.1.x. Had conflicts on dictionary.txt
Comment #195
luke.leberI feel that the migration from additional properties to third party settings needs to be benchmarked with as much scrutiny as the community can provide. Deprecating
$additionalis not something to take lightly for huge sites.Here's a (hopefully, exaggerated) persona that might be able to help...
Comment #196
vipin.j commentedPatch #192 was fixed for failure while patch application, due to test case file changes DefaultsSectionStorageTest.php, in RC1 release. This patch is applicable for version 10.1.x-dev.
Comment #197
heddnRe #196: I don't see where there is currently an upgrade path for overrides. That would be up to each contrib or custom module to build into its handling of the deprecation. If
custom_lb.moduleadds some$additionalitems, I would expect/hope that it would handle the deprecation.Comment #198
heddnRe-roll for 11.x and fixing version strings in deprecations.
Comment #199
chris burge commentedRe #197, see
layout_builder_component_attributes_uninstall()in the Layout Builder Component Attributes modules. My plan is to adapt that code to move settings in$additionalto third-party settings. It covers entity view displays, as well as overrides (including all revisions).That said, it hasn't been tested as contemplated in #195. I'm happy to collaborate on that point.
Comment #201
heddnNo interdiff on the re-roll. The only conflicts where in cspell and were trivial to resolve manually.
Comment #202
smustgrave commentedCC failures, but #198 appeared to have some test failures.
Comment #205
pyrello commentedI noticed the code quality warnings in the MR. Nice! I fixed the ones I could figure out off the top of my head how to fix. The others I'm not sure how to deal with. While we are not removing the $additional property, are we doing anything to convert the incoming attributes to third party settings? Need someone who understands this better to weigh in.
Comment #207
milos.kroulik commentedJust a note - the latest state of MR seems to be applying cleanly to 10.2.x (which isn't the case with patches above it).
Comment #208
luke.leberI have some performance details on mass update hooks to layout overrides. Over in the issue to add UUIDs to sections, updating 50,000 layout overrides can put a site into maintenance mode for a whopping approximately 15 minutes.
For stakeholders, that means downtime. $.02
Comment #209
actuallyam commentedCould someone make a patch for drupal 10.2 version? Is there possibility that this patch comes for drupal 10.2 and possibly also compability for php 8.2? With 8.2 php there is a php info in logs:
Comment #210
capysara commented@ActuallyAM it gets confusing when there are patches posted along with MRs, but you can create a patch for your own testing. Find the MR you need at the top of this issue, then click the link for Plain Diff, and save as a .patch file.
Comment #211
jjpost commentedPatch of the latest MR like capysara suggested
Comment #213
rahaf albawab commentedThis is a reroll of #211 for 10.3.x
Comment #214
carolpettirossi commentedApplying this patch from #213 was helpful in make layout_builder_styles work properly when upgrading to 10.3.1.
I was getting
and also
When trying to create a new block or edit an existing block.
Comment #215
carolpettirossi commentedOne note: the patches from MR 8474 or comment #211 work and solve the problem. However, a PHP 8.2 deprecation notice remains as stated on #209:
Deprecated function: Creation of dynamic property Drupal\layout_builder\SectionComponent::$legacyAdditionalModuleKey is deprecated in Drupal\Core\Entity\Sql\SqlContentEntityStorage->loadFromDedicatedTables() (line 1269 of /web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php)Comment #217
carolpettirossi commentedDrupal 10.3 and PHP 8.2 compatibility MR has been created: MR 8724. Can someone please review?
Comment #218
papagrandeComment #221
acbramley commentedWe have 3 patches, 8 branches, and 6 MRs on this issue. That's basically impossible for anyone to review or know what to contribute to. Can we please get these cleaned up and documented in the IS?
Comment #222
flyke commentedNone of the branches (diff files) or patches seem to apply to Drupal 11.0.5
Comment #223
flyke commentedI tried creating a patch for 11.0.5 but I did it wrong.
I thought that I just had to checkout the current issue branch, and create a diff between that and the 11.0.5 tag.
Of course that results in the diff containing every change of 11.x since 11.0.5. D'oh.
I guess the only way to have a working patch file for 11.0.5 is checking out 11.0.5, looking at all the changes in the current latest patch and manually applying them and then create a patch file ?
Comment #224
flyke commentedComment #225
flyke commentedUpdate, I think I got it how to create a patch for 11.0.5 with minimal effort.
- checkout 11.0.5 in a clean Drupal repo clone:
git checkout tags/11.0.5- copy the (incompatible) 11.x diff file in the root (
5053.diff)- use this command to apply all the parts the patch that do work:
git apply --reject --index 5053.diff- Notice that there is only 1 error:
error: core/misc/cspell/dictionary.txt: does not match index- manually edit dictionary.txt with the necessary changes (add 4 missing words in the right place)
- remove the
5053.difffile- create a patch
git diff > 3015152-225.patchTested and it works on 11.0.5
Comment #231
acbramley commentedAttempting to consolidate MRs to make this issue manageable and hiding all patches
Work must go into 11.x first and then it will be backported to 10.3.x if possible, adding multiple MRs to this issue is just making it harder to contribute to and review. Please continue working on https://git.drupalcode.org/project/drupal/-/merge_requests/5053/diffs as this seems to be the most up to date version from what I can see.
Comment #233
acbramley commentedComment #234
heddnUpdate tests added and are green now. IS seems up to date. Ready for review.
Comment #235
flyke commentedIf I use MR 5053 on Drupal 11.1.1 I get multiple notices on each page:
Deprecated: Creation of dynamic property Drupal\layout_builder\SectionComponent::$legacyAdditionalModuleKey is deprecated in /var/www/html/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php on line 1264Strangely, If I search my entire codebase for 'legacyAdditionalModuleKey' there are no results. I have cleared caches and updated the database multiple times after updating from D10.4 to D11.1
Comment #236
flyke commentedIn my case, these errors came from existing Section Components in my project that seem to had a legacyAdditionalModuleKey property. That was inside the serialized data inside the node__layout_builder__layout table in the layout_builder__layout_section field.
I created a helper function that identifies section components and removes that legacyAdditionalModuleKey if it's present. This works but please note the comment below that this code currently does not fix revisions.
First, I load all layoutbuilder nodes, then loop them, get the layout, get the sections, loop them, get the components, loop them, then check. If a component has the legacyAdditionalModuleKey then I create a new one that does not contain it, place it on the position of the old one and remove the old one. There might be a way better way to get all existing Section Components but you do need to save the node after editing the sections of it so this might be the correct way to go, not sure. At least it works for me ;-).
I run this code by running:
drush php:eval "_fix_sections_d11();".Here is the code:
Comment #237
acbramley commented@flyke thanks for that, I was investigating how to remove this key myself for quite a while and came up short. The main issue I was running into is that when you save the node, the LayoutSectionItemList::equals was stopping the old data from being overwritten because toArray drops the key, therefore it doesn't save. However, since you're creating a new component (and therefore new UUID) it should work!
You also need to do this for every revision, otherwise you get the same errors on the revisions page as well.
Comment #238
flyke commentedA bit of a relief to know that I'm not the only one facing this problem. I did spend quite a lot of time figuring this out and coming up with a working solution. Glad that it has helped someone. Maybe someone could use my code as a starting point to make it more elegant/efficient and include revisions.
I updated the code above because the first version relied on a custom service to get all layoutbuilder nodes. The updated version does not rely on other custom code so anyone can copy/paste this and it should work.
Comment #239
acbramley commentedThanks so much @flyke, I've created a gist that improves upon your solution a bit with the following:
1. Makes it a batched process to avoid memory issues
2. Filters the initial query so only revisions with that key are loaded
3. Generates a new UUID for the new section, I was having issues where some components were being dropped off without this.
This uses an entity migration helper that we often use for these kind of operations, it's flexible enough to apply to any sort of data migration involved with entities :)
https://gist.github.com/acbramley/53578b18b27466f1b508aedb12907b5e
I've added this to the IS.
Comment #241
flyke commentedHi @acbramley I don't understand how to use your method, more specifically, how to run it.
I have an enabled custom module 'starterkit_helper'.
In there, I created starterkit_helper.post_update.php file. The contents from the first file of your gist.
Of course inside i changed 'my_profile' to 'starterkit_helper'.
I also created a file starterkit_helper/src/MyProfileUpdateUtils.php. The contents from the second file of your gist.
Of course inside i changed 'my_profile' to 'starterkit_helper'.
I ran
drush crand thendrush updb -ybut nothing happened, nothing run, and the errorsDeprecated : Creation of dynamic property Drupal\layout_builder\SectionComponent::$legacyAdditionalModuleKey is deprecated in /var/www/html/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php on line 1264remain
How do I run this code ?
For now, since the mymodule.post_update.php file did nothing in my case, I added the contents of it to my .module file (of my custom starterkit_helper module). I gave the $sandbox parameter an empty array as default value:
function starterkit_helper_profile_post_update_remove_legacy_key(array &$sandbox = []): TranslatableMarkup {And then I ran:
drush php:eval "starterkit_helper_profile_post_update_remove_legacy_key();"Unlike my code, there is no output at all unfortunatly, but the errors are gone now.
Comment #242
acbramley commentedHey @flyke those steps seem correct to me, the only thing would be perhaps if you had the post update function in code before you enabled the module, Drupal may have marked that as already run. Try renaming the function and running drush updb again.
Comment #243
luke.leberI wonder if the gist in #239 could be optimized by operating on the layout builder section storage tables and bypassing the Entity API? The SectionStorage can be loaded and saved independently of the content entity it's attached to I believe.
Generally, saving content entities is MAJORLY slow comparatively. I plan on running additional benchmarking on this at some point as we have over a quarter million sections to churn through when this finally lands. 🤞
Comment #244
acbramley commentedFeel free to optimise away @luke.leber :) We only had about 1700 revisions to get through. Yes it's slower but this was the easiest approach for us without sinking too much time.
Comment #245
luke.leberFeel free to review, but this approach seems very reasonable to me in terms of performance 💪. This operates at a very low level, so it's very likely that this first stab is not 100% perfect.
Business logic encapsulated in a helper service
Service configuration boilerplate
Sample post update hooks for *one* entity type
Let's do this thing @ 10,000 records per batch.
15 seconds to churn through over 210,000 records seems agreeable to me!
Comment #246
flyke commentedNot sure what I'm doing wrong, but @luke.leber's method executed without errors but it did not solve anything in my project.
On the left side of the screenshot you can see in the terminal below that it executed the 2 updates.
On the right side of the screenshot: that is refreshed after the updates were executed. You can see the errors are still there in my case.
After this, I tried my own code from #236 and that actually fixed and removed all the errors.
Comment #247
smustgrave commentedAppears to need a rebase
Can the CR be updated though it doesn't really seem to line up with the MR or explain the change to me
If you are another contributor eager to jump in, please allow the previous poster at least 48 hours to respond to feedback first, so they have the opportunity to finish what they started!
Comment #249
stomusicReroll for 11.x
Comment #250
acbramley commented@smustgrave anything in particular you're unsure of in the CR? I've modified the title slightly and updated versions
Comment #251
acbramley commentedComment #252
smustgrave commentedI think the CR reads fine now and cleared it up for me. Fingers crossed.
Comment #253
bkosborneThanks Luke for providing the example migration code. I agree that manually unserializing, reserializing, and saving the data directly to the database bypassing the entity API is the only sane way to do an upgrade path for layout overrides. We run 1,000 sites with what I imagine contain hundreds of thousands of overrides across them (including revisions). Entity load/save will simply take too long.
I hate to do this, but I'm setting this back to Needs Work to at least have the CR updated to provide the critical information that modules that were relying on "additional" need to write their own upgrade path for layout overrides to switch TPS. I say this as a maintainer of the Layout Builder Styles module which critically relies on
additional. Also, given that the upgrade path should essentially be identical for all contrib modules, perhaps it should actually be included in the MR. The current upgrade path in this MR only covers the default entity view displays.I also want to throw this out there: What if we just don't deprecate
additionalat all? Just leave it there and discourage it's use in comments and point people at TPS instead. I'm thinking of all the hours of time developers and module maintainers will need to spend on this upgrade path and it hurts to think about.Comment #254
acbramley commented@bkosborne I understand the concern but I don't think we can automate that upgrade path from core. We aren't removing additional, we're deprecating it so modules will be aware they need to change. How would we know how modules are using those additional settings? If they are doing
$component->get('foo');and we're automatically moving additional -> tps then that code would suddenly be broken, they need to change that to getThirdPartySetting.Comment #255
heddnre #253/254: I came to the exact same conclusion as Adam after I had to convert some custom code to using tps. It was very specific to that custom module. I also ended up writing the upgrade path as a BC compliant solution so it would convert on page load. Of course, that is all very custom to that site's use case. There could be a hundred ways to convert over.
Secondly, is there any value in converting? Yes. If you ever tried to enforce config schema on additional vs tps, you'll immediately see that its impossible with additional. I've been waiting for tps on sections for several years for just that reason. Sure it will be painful. Arguably though we shouldn't have use additional in the first place. But we live and learn.
Comment #256
chris burge commentedAs the maintainer for the Layout Builder Component Attributes modules, who also has contributed code to this issue, my vote is to commit. It'll be up to contrib to handle upgrade paths. The code provided by @luke.leber is what I'm planning on using. (@luke.leber THANK YOU for sharing that code btw.) It's performant and can handle a large number of records. Modules using the
additionalproperty will have until D12 to address the deprecation.Comment #257
luke.leberI would like to be linked to one other core commit that would force site owners to run multiple content updates on every single revision of every single content entity on their site.
In the past 10 years I cannot think of one. IMO this sets a very dangerous precedent..
What happens if MYSQL goes away mid-update? Race conditions? Many known race conditions exist in core. This isn't running an "atomic" SQL operation. Lots of stuff can and likely will go wrong in the wild.
Comment #258
acbramley commentedThanks for the valuable feedback everyone, I think this can go back to RTBC then.
Comment #259
heddn#257: I don't think you technically _must_ create a hook_update. You could just keep legacy code, check a Settings.php key or State key or something to see if you should trigger the legacy `additional` logic. You could also write a cron queue job that processes revisions nightly between 10pm and 4am. There are lots of options here. Performance of running the update isn't the biggest concern to me. I've added a link in the CR to comment #245 who might that helpful.
For other places where this happened, look at the Group v2/v3 => v4 upgrade path. Its a bit gnarly but seems to work.
Comment #260
luke.leberAtlanta would be a great space to discuss this. Between LB styles, LB component attributes, and who knows what else in contrib space, how would contrib even coordinate all of these upgrade paths? Would every module do it independently? Only for their third party settings? What about custom stuff too?
I could see some sites needing like 4 or 5 iterations of saving every revision to make this work in contrib/custom...it just seems like a very messy thing for core to put the burden on site owners with.
If it's not an easy upgrade (read: something that non-technical site owners would have to spend $$$ on an agency to custom code a migration for), odds are trust will be damaged. In today's super competitive market, damaging trust shouldn't be downplayed -- especially if migrating to a competitor's solution ends up being cheaper to the business.
$.02 😥
Comment #261
nod_Since there are upgrade path concerns, tagging for RM review
Comment #262
flyke commentedI myself use MR5053 on several D11.1.6 projects that use layoutbuilder and lots of layoutbuilder contrib modules like layout_builder_at, layout_builder_blocks, layout_builder_browser, layout_builder_ipe, layout_builder_modal, bootstrap_layout_builder etc. For me MR5053 is working on all those projects. I hope others can chime in and confirm that the MR is working for them too.
Comment #263
catchJust seen that this is tagged for release manager review.
The update in the MR will only run on layouts in the database, not shipped with modules, it needs to implement the presave pattern used by other config entity updates. Moving to needs work for that. #3521618: Add generic interface + base class for upgrade paths that require config changes and linked issues have some discussion.
Not sure what I think yet about content entity upgrade path, but a similar problem came up in the experience builder queue recently, which led to opening #3521221: Block plugins need to be able to update their settings in multiple different storage implementations against core.
Starting to think we need some kind of generalised just-in-time updates on content entity saves for things like this (similar to presave for config entities, would probably need to happen in presave too), and then potentially a UI and/or drush command that would put every revision of every entity of a specific type into a queue to to be resaved - ideally with a way to calculate whether changes are needed before actually saving it. But we're far off from that at the moment.
Comment #264
thiagomoraesp commentedHello everyone, the gist in the description didn't fixed the deprecated warning for me, @luke.leber logic also didn't worked (they execute but didn't changed anything in my database), so i adapted both to work together on a single logic that i want to share with you in this gist (working on 10.4.7):
https://gist.github.com/D41196829/1837b740e89f81c17277c072db6f3b1f
Comment #265
flyke commentedThe current MR does not apply to D11.2.0 by the way, in case people are wondering.
Comment #266
acbramley commentedI've rebased the branch, fixed new issues introduced by AddComponentTest and the config action, and updated to the presave pattern.
Let's see if we can get this in before the comments OOM the page XD
Comment #267
acbramley commentedI don't know how we can support throwing a deprecation here with the presave pattern.
All the test failures are because of this deprecation because there is no way to know if the display didn't already have third party settings (i.e it needs to be saved). Once the display is loaded, the section components will automatically have an empty array for third_party_settings because of the default value in the constructor.
Comment #268
xjmComment #269
hmdnawaz commentedpatch for 11.2.2 without tests
Comment #270
hmdnawaz commentedComment #271
acbramley commentedI've removed the upgrade path here because it doesn't seem possible to have an upgrade path that only updates view displays that do not contain the third_party_settings key in some of the components. This is because as soon as the view display entity is loaded, the third party settings are set to an empty array (because of
protected $thirdPartySettings = [];). This means that it's impossible to throw a deprecation correctly in the presave hook, unless we do some whacky stuff with that default value and try to ensure a NULL doesn't make it into the config which IMO is not worth it.I've tested locally and view displays that have components without the
third_party_settingskey continue to pass config validation. I tested this with Umami by reverting one of the displays and running DemoUmamiProfileTest which does config schema checks.The only downside to this is that when someone saves a view display with layout builder enabled, every component will have this key automatically added, rather than it being added via an update hook.
We could also keep the update hook and mark every LB enabled view display as needing an update and simply don't throw a deprecation.
Comment #272
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #273
acbramley commentedComment #274
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #275
acbramley commentedComment #276
carolpettirossi commentedI wasn't able to apply the patch on the Drupal stable release: 11.2.4.
If someone needs to apply the patch to the same version, I'm attaching it here.
Comment #277
carolpettirossi commentedSorry, my bad, the correct patch is attached.
Comment #278
carolpettirossi commentedFor the ones using this patch for quite some time, you may face this:
Deprecated: Creation of dynamic property Drupal\layout_builder\SectionComponent::$legacyAdditionalModuleKey is deprecated in /var/www/html/docroot/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php on line 1264Here's a patch to solve that Deprecated notice.
Comment #279
acbramley commented@carolpettirossi there's a note in the issue summary about that under Known issues. I would not recommend continuing to run a patch that contains that property as you'll need to run it foreverr.
Comment #281
vensiresI needed this for upgrading a website which already used it from its earlier versions. There was no patch applying for 10.5.x though. After rebasing MR!8724 it applied successfully.
I still favor what @acbramley already said in #231 of course: "Work must go into 11.x first and then it will be backported to 10.3.x if possible". So, focus should stay on MR!5053.
Comment #282
vensiresAlso adding as hidden the patch for v10.5.x I previously forgot.
Comment #289
vensiresPrevious patch for 10.5.x failed when using composer patches v2.0. Rerolled for 10.6.x.
Comment #290
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #292
acbramley commentedAll the new MRs and patches tripped the bot.
Comment #293
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #294
acbramley commentedBot is trying to apply an MR that has been closed.
Comment #295
mkdok commentedPatch for 11.3.2
Comment #297
smustgrave commentedMR mentions removing some code with 12.x opens. Main is open so should that just be made?
Comment #298
acbramley commentedTidied up the deprecation messages and merged main in. Main is open but 12.0.x is not (we can't remove code until that is right?), I've left 1 comment in as a reminder to remove
additionalusage.Comment #299
acbramley commentedNeeds RM review was added back in https://www.drupal.org/project/drupal/issues/3015152#comment-16085597 when there was an upgrade path. We removed that so I'm removing the tag. See #271 for reasons behind removing the upgrade path.