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.

CommentFileSizeAuthor
#295 3015152-11.3.2-no_tests.patch16.95 KBmkdok
#293 3015152-nr-bot_flbqamog.txt91 bytesneeds-review-queue-bot
#290 3015152-nr-bot_mfh0lnce.txt91 bytesneeds-review-queue-bot
#289 3015152-support_third_party_settings_for_components_within_a_section-v10.6-MR14167.patch28.33 KBvensires
#282 3015152-support_third_party_settings_for_components_within_a_section-v10.5-MR8724.patch31.1 KBvensires
#278 3015152-support_third_party_settings_11.2.4_without_tests_support_old_versions.patch9.84 KBcarolpettirossi
#277 3015152-support_third_party_settings_11.2.4_without_tests.patch9.71 KBcarolpettirossi
#276 3015152-support_third_party_settings_11.2.4_no_tests.patch9.72 KBcarolpettirossi
#274 3015152-nr-bot_2yeuipj8.txt90 bytesneeds-review-queue-bot
#272 3015152-nr-bot_llrm0jii.txt90 bytesneeds-review-queue-bot
#270 3015152-270.patch23.56 KBhmdnawaz
#269 5053.patch19.58 KBhmdnawaz
#4 3015152-tps-4.patch7.82 KBjian he
#5 3015152-tps-5.patch7.79 KBjian he
#5 interdiff-5.txt577 bytesjian he
#16 3015152-tps-16.patch7.74 KBsegovia94
#19 3015152-tps-19.patch11.41 KBsegovia94
#19 interdiff_16-19.txt4.69 KBsegovia94
#22 3015152-tps-22.patch10.76 KBaleksip
#22 interdiff-3015152-19-22.txt691 bytesaleksip
#24 3015152-tps-24.patch11.43 KBaleksip
#24 reroll-diff-3015152-19-24.txt7.79 KBaleksip
#26 3015152-tps-26.patch11.58 KBjoey-santiago
#41 3015152-40.patch10.39 KBravi.shankar
#48 3015152-48.patch10.43 KBadityasingh
#48 interdiff_40-48.txt513 bytesadityasingh
#58 3015152-58.patch17.5 KBchris burge
#58 interdiff-3015152-58-48.txt10.97 KBchris burge
#67 3015152-67.patch19.72 KBchris burge
#67 interdiff-3015152-67-58.txt9.12 KBchris burge
#75 3015152-75.patch49.1 KBchris burge
#75 interdiff-3015152-75-67.txt34.15 KBchris burge
#77 3015152-77.patch51.56 KBchris burge
#77 interdiff-3015152-77-75.txt12.39 KBchris burge
#79 3015152-79.patch53.24 KBchris burge
#79 interdiff-3015152-79-77.txt2.18 KBchris burge
#81 3015152-81.patch53.53 KBchris burge
#81 interdiff-3015152-81-79.txt2.13 KBchris burge
#82 3015152-82.patch53.53 KBchris burge
#82 interdiff-3015152-82-81.txt620 byteschris burge
#86 3015152-86.patch51.93 KBakalam
#90 3015152-tps-89.patch53.39 KBtim.plunkett
#103 3015152-tps-103.patch55.52 KBmxh
#103 interdiff-89-103.txt6.73 KBmxh
#105 3015152-tps-105.patch56.07 KBanmolgoyal74
#105 interdiff_103_105.txt475 bytesanmolgoyal74
#109 3015152-tps-109.patch55.91 KBmxh
#109 interdiff-105-109.txt698 bytesmxh
#111 3015152-tps-111.patch55.94 KBmxh
#111 interdiff-109-111.txt2.7 KBmxh
#111 interdiff-89-111.txt9.29 KBmxh
#114 3015152-tps-114.patch54.98 KBmxh
#114 interdiff-89-114.txt5.35 KBmxh
#114 interdiff-111-114.txt4.92 KBmxh
#116 3015152-tps-9.2.x-116.patch58.18 KBmxh
#116 interdiff-114-116.txt3.2 KBmxh
#124 3015152-tps-9.3.x-124.patch58.18 KBsegovia94
#124 interdiff_116-124.txt7.1 KBsegovia94
#128 3015152-tps-9.3.x-128.patch58.12 KBfeng-shui
#139 interdiff_128-139.txt38.43 KBheddn
#139 3015152-139.patch27.85 KBheddn
#142 interdiff_139-142.txt2.85 KBheddn
#142 3015152-142.patch27.46 KBheddn
#144 interdiff_142-144.txt12.92 KBheddn
#144 3015152-144.patch29.39 KBheddn
#145 interdiff_144-145.txt1.3 KBheddn
#145 3015152-145.patch29.39 KBheddn
#147 interdiff_145-147.txt4.9 KBheddn
#147 3015152-147.patch34.03 KBheddn
#150 interdiff_147-150.txt7.2 KBheddn
#150 3015152-150.patch33.72 KBheddn
#159 reroll_diff_150-159.txt3.27 KBravi.shankar
#159 3015152-159.patch33.74 KBravi.shankar
#164 3015152-164.patch40.57 KBravi.shankar
#165 3015152-165.patch33.72 KBravi.shankar
#167 reroll_diff_150-165.txt1.92 KBravi.shankar
#172 drupal-9.4.x-3015152-172.patch0 byteshswong3i
#173 drupal-9.4.x-3015152-173.patch33.61 KBhswong3i
#174 drupal-9.4.x-3015152-174.patch28.76 KBhswong3i
#180 3015152-180.patch33.73 KBvsujeetkumar
#182 3015152-182.patch29.76 KBAnkit.Gupta
#183 3015152-183.patch29.76 KBamarlata
#184 interdiff_183-184.txt811 bytesRatan Priya
#184 3015152-184.patch29.76 KBRatan Priya
#188 3015152-nr-bot.txt145 bytesneeds-review-queue-bot
#189 3015152-189.patch29.76 KBamjad1233
#189 interdiff_184_189.txt157 bytesamjad1233
#191 3015152-191.patch29.77 KBamjad1233
#192 3015152-192.patch29.71 KBheddn
#196 3015152-196.patch29.82 KBvipin.j
#198 3015152-198.patch29.77 KBheddn
#198 interdiff_196-198.txt5.46 KBheddn
#201 3015152-201.patch29.78 KBheddn
#211 3015152-211.patch31.03 KBjjpost
#213 3015152-213.patch30.16 KBrahaf albawab
#223 3015152-223.patch2.51 MBflyke
#225 3015152-225.patch29.72 KBflyke
#236 legacyAdditionalModuleKey.png214.34 KBflyke
#246 sectioncomponents-error.png310.5 KBflyke
#249 3015152-249.patch41.69 KBstomusic

Issue fork drupal-3015152

Command icon 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:

Comments

bkosborne created an issue. See original summary.

tim.plunkett’s picture

Status: Active » Closed (duplicate)
tedbow’s picture

Status: Closed (duplicate) » Active

Splitting 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

jian he’s picture

Status: Active » Needs work
StatusFileSize
new7.82 KB

Only have functional code, does not have testing code yet. Just want to make things working. I am idiot for writing testing code.

jian he’s picture

Status: Needs work » Needs review
StatusFileSize
new7.79 KB
new577 bytes

Fix failed testing.

Status: Needs review » Needs work

The last submitted patch, 5: 3015152-tps-5.patch, failed testing. View results

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

bkosborne’s picture

This 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.

tim.plunkett’s picture

I don't think there is any value to additional if we can have TPS.
The problem is how to provide BC in the meantime.

tim.plunkett’s picture

Issue tags: +Blocks-Layouts
jwilson3’s picture

Field 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?

jwilson3’s picture

Cross-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:

  $render_display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
  $field_display = $render_display->getComponent($field_name);
  var_dump($field_display['third_party_settings']);

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:

  $view_display = \Drupal::entityTypeManager()
    ->getStorage('entity_view_display')
    ->load($entity->getEntityType()->id() . '.' . $entity->bundle() . '.' . $view_mode);
 

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.

jwineichen’s picture

Patch from #5 is working with Block Class with additional patch on that module (https://www.drupal.org/project/block_class/issues/2998114).

murz’s picture

I 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.

altrugon’s picture

Status: Needs work » Reviewed & tested by the community

Just tested and indeed works fine. Changing ticket status.

segovia94’s picture

StatusFileSize
new7.74 KB

This is a reroll of #5 for 8.8.x.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 16: 3015152-tps-16.patch, failed testing. View results

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

segovia94’s picture

StatusFileSize
new11.41 KB
new4.69 KB

Umami 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.

segovia94’s picture

Status: Needs work » Needs review
jhedstrom’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

This is looking good. I like that the additional property is properly deprecated :)

One note on the test modifications though:

+++ b/core/modules/layout_builder/tests/src/Functional/Update/LayoutBuilderEnableUpdatePathTest.php
@@ -45,6 +45,7 @@ public function testRunUpdates() {
+              'third_party_settings' => [],

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.

aleksip’s picture

StatusFileSize
new10.76 KB
new691 bytes

Removed third_party_settings from LayoutBuilderEnableUpdatePathTest.

jhedstrom’s picture

Sorry, 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 the LayoutBuilderEnableUpdatePathTest , but for that to then pass, we'll need an update hook that adds third_party_settings to existing installations/configs.

aleksip’s picture

StatusFileSize
new11.43 KB
new7.79 KB

@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?

aleksip’s picture

Status: Needs work » Needs review
joey-santiago’s picture

Version: 8.9.x-dev » 8.8.x-dev
StatusFileSize
new11.58 KB

Re-rolled the patch against 8.8.0. Hope this is fine :)

mark.labrecque’s picture

Tested 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 :)

mark.labrecque’s picture

Status: Needs review » Reviewed & tested by the community
chris burge’s picture

Issue tags: -Needs tests

This is going to need a change record: See https://www.drupal.org/node/3035096 as an example.

mark.labrecque’s picture

Issue tags: +Needs change record
mark.labrecque’s picture

Added a draft change record for this patch. Please review it here and add more detail if it is needed.

mark.labrecque’s picture

Issue tags: -Needs change record
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
--- a/core/modules/layout_builder/config/schema/layout_builder.schema.yml
+++ b/core/modules/layout_builder/config/schema/layout_builder.schema.yml

@@ -52,6 +52,11 @@ layout_builder.component:
+      sequence:
+        type: ignore

I'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.

chris burge’s picture

What about the following?

@@ -52,6 +52,11 @@ layout_builder.component:
+      sequence:
+        type: 'layout_builder.component.third_party.[%key]'

This works in my testing with the following contrib schema:

layout_builder.component.third_party.my_key:
  type: mapping
  label: My label
  mapping:
    classes:
      type: string
      label: My classes

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:

/**
 * Clear caches due to config schema additions.
 */
function layout_builder_post_update_component_third_party_settings_schema() {
  // Empty post-update hook.
}
anybody’s picture

Thank 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?

morbus iff’s picture

Version: 8.8.x-dev » 8.9.x-dev

The current patch in #26 is applying cleanly in 8.9.0.

larowlan’s picture

Version: 8.9.x-dev » 9.1.x-dev

New features will only go into 9.1.x now.

amjad1233’s picture

Issue tags: +Bug Smash Initiative
ravi.shankar’s picture

Assigned: Unassigned » ravi.shankar
larowlan’s picture

Issue tags: -Bug Smash Initiative

This is a feature, we're hoping to keep the Bug Smash tag just for Bugs. But feel free to help move this along!

ravi.shankar’s picture

Assigned: ravi.shankar » Unassigned
StatusFileSize
new10.39 KB

Added reroll of patch #26 for Drupal 9.1.x.

Still needs work for #33.

larowlan’s picture

Looking at how we generally do third-party settings for config-objects - core's entity schema for config_entity type has this

third_party_settings:
      type: sequence
      label: 'Third party settings'
      sequence:
        type: '[%parent.%parent.%type].third_party.[%key]'

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

contact.form.*.third_party.contact_storage:
  type: mapping
  label: 'Contact form redirection'
  mapping: {details here}

So I think we need to do similar but also

  • Add a test module that interacts with components via third-party
  • Add a schema to that module
  • verify in a test that the schema is correctly applied
chris burge’s picture

Issue tags: +Needs tests

The '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:

/**
 * Clear caches due to config schema additions.
 */
function layout_builder_post_update_component_third_party_settings_schema() {
  // Empty post-update hook.
}

Agreed we need to add test coverage. (Tag added to issue).

The only test-related code in the patch is below:

--- a/core/modules/layout_builder/tests/src/Kernel/DefaultsSectionStorageTest.php
+++ b/core/modules/layout_builder/tests/src/Kernel/DefaultsSectionStorageTest.php
@@ -115,7 +115,7 @@ public function providerTestAccess() {
         'layout_onecol',
         [],
         [
-          'first-uuid' => new SectionComponent('first-uuid', 'content', ['id' => 'foo'], ['harold' => 'maude']),
+          'first-uuid' => new SectionComponent('first-uuid', 'content', ['id' => 'foo'], ['harold' => 'maude'], ['layout_builder_defaults_test' => ['harold' => 'kumar']]),
         ],
         ['layout_builder_defaults_test' => ['which_party' => 'third']]
       ),
geek-merlin’s picture

> 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:

    third_party_settings:
      type: sequence
      label: 'Third party settings'
      sequence:
        type: '[%parent.%parent.%type].third_party.[%key]'

(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!

chris burge’s picture

@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.

geek-merlin’s picture

+++ b/core/modules/layout_builder/config/schema/layout_builder.schema.yml
@@ -52,6 +52,11 @@ layout_builder.component:
+        type: ignore

I think this line has to be changed to:

        type: '[%parent.%parent.%type].third_party.[%key]'
adityasingh’s picture

Assigned: Unassigned » adityasingh
adityasingh’s picture

StatusFileSize
new10.43 KB
new513 bytes

Updated patch as per the changes suggested in #46, please review.

adityasingh’s picture

Assigned: adityasingh » Unassigned
Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 48: 3015152-48.patch, failed testing. View results

geek-merlin’s picture

Now that we have a schema, the test fails as it should.

+++ b/core/modules/layout_builder/tests/src/Kernel/DefaultsSectionStorageTest.php
@@ -115,7 +115,7 @@ public function providerTestAccess() {
+          'first-uuid' => new SectionComponent('first-uuid', 'content', ['id' => 'foo'], ['harold' => 'maude'], ['layout_builder_defaults_test' => ['harold' => 'kumar']]),

This adds a TPS for which no schema exists.

The above needs a schema like

layout_builder.component.third_party.layout_builder_defaults_test:
  type: mapping
  mapping:
    harald:
      type: string
      label: Some arbitrary string.
chris burge’s picture

+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:

2) Drupal\Tests\layout_builder\Kernel\DefaultsSectionStorageTest::testAccess with data set "view, enabled, data" (true, 'view', true, array(Drupal\layout_builder\Section Object (...)))
Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for core.entity_view_display.entity_test.entity_test.default with the following errors: core.entity_view_display.entity_test.entity_test.default:third_party_settings.layout_builder.sections.0.components.first-uuid.third_party_settings._layout_builder missing schema

It's the result of how we're dealing with the $additional parameter in the SectionComponent constructor:

-  public function __construct($uuid, $region, array $configuration = [], array $additional = []) {
+  public function __construct($uuid, $region, array $configuration = [], array $additional = [], array $third_party_settings = []) {
     $this->uuid = $uuid;
     $this->region = $region;
     $this->configuration = $configuration;
     $this->additional = $additional;
+    if ($additional) {
+      $third_party_settings[$this->legacyAdditionalModuleKey] = $additional;
+    }
+    $this->thirdPartySettings = $third_party_settings;

When we pass a value as the $additional parameter, 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.

chris burge’s picture

We also need to add a deprecation tag to the $additional property:

  /**
   * Any additional properties and values.
   *
+  * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0.
+  *   Additional component properties should set via ::setThirdPartySetting().
+  *
+  * @see https://www.drupal.org/node/3100177
+  *
   * @var mixed[]
   */
  protected $additional = [];
geek-merlin’s picture

I did not research how we want to handle BC of $additional, bu i suppose we have to keep it.
So let's do:

layout_builder.component.third_party._layout_builder:
  type: ignore
  label: 'Deprecated: Additional data'
  # TODO Add deprecated key once https://www.drupal.org/project/drupal/issues/2997100 lands.

and remove that chunk instead:

+++ b/core/modules/layout_builder/config/schema/layout_builder.schema.yml
@@ -52,6 +52,11 @@ layout_builder.component:
     additional:
       type: ignore
       label: 'Additional data'
chris burge’s picture

It'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 with SectionComponent->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->additional for 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 $legacyAdditionalModuleKey private property and all of its uses.

geek-merlin’s picture

I can follow the reasoning in #55 and it makes sense to me.

chris burge’s picture

Assigned: Unassigned » chris burge

I'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.

chris burge’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new17.5 KB
new10.97 KB

Updated 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:

$ phpcs --standard=Drupal,DrupalPractice src/SectionComponent.php

FILE: ...-lb-component-tps/web/core/modules/layout_builder/src/SectionComponent.php
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
 148 | ERROR | The trigger_error message 'Additional component properties
     |       | should set via ::setThirdPartySetting().' does not match the
     |       | relaxed standard format: %thing% is deprecated in
     |       | %deprecation-version% any free text %removal-version%.
     |       | %extra-info%. See %cr-link%
--------------------------------------------------------------------------------

Time: 133ms; Memory: 10MB

Code change:

- @trigger_error('Additional component properties should set via ::setThirdPartySetting().', E_USER_DEPRECATED);
+ @trigger_error('Setting additional properties is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Additional component properties should set via ::setThirdPartySetting(). See https://www.drupal.org/node/3100177', E_USER_DEPRECATED);
tim.plunkett’s picture

Status: Needs review » Needs work

I 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...

  1. +++ b/core/modules/layout_builder/src/SectionComponent.php
    @@ -65,13 +80,16 @@ class SectionComponent {
    +  public function __construct($uuid, $region, array $configuration = [], array $additional = [], array $third_party_settings = []) {
    

    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.

  2. +++ b/core/modules/layout_builder/src/SectionComponent.php
    @@ -65,13 +80,16 @@ class SectionComponent {
         $this->additional = $additional;
    

    This should be wrapped in a !empty and get a trigger_error too

  3. +++ b/core/modules/layout_builder/tests/src/Unit/SectionComponentTest.php
    @@ -20,6 +21,51 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
    +  protected $component;
    ...
    +    $this->component = new SectionComponent(
    

    This is never reused outside the method.

  4. +++ b/core/modules/layout_builder/tests/src/Unit/SectionComponentTest.php
    @@ -20,6 +21,51 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
    +        'Chotchkie\'s' => [
    

    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.

  5. +++ b/core/modules/layout_builder/tests/src/Unit/SectionComponentTest.php
    @@ -20,6 +21,51 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
    +    $this->section = new Section(
    +      'layout_onecol',
    +      [],
    +      [
    +        $this->component,
    +      ],
    +    );
    

    That's some excessive wrapping. Could probably just be a one-liner.

  6. +++ b/core/modules/layout_builder/tests/src/Unit/SectionComponentTest.php
    @@ -68,4 +114,147 @@ class SectionComponentTest extends UnitTestCase {
    +  public function providerTestGetThirdPartySettings() {
    ...
    +    $data[] = [
    ...
    +  public function providerTestGetThirdPartySetting() {
    ...
    +    $data[] = [
    

    Please add explanatory array keys for the data providers, explaining what each is testing.

chris burge’s picture

I 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

It'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.

#59.1: 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.

As long as we add $third_party_settings to the end of the constructor signature, we don't need a BC layer. We're designating $additional as 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:

  public function __construct($uuid, $region, array $configuration = [], array $additional = [], array $third_party_settings = []) {

D10 constructor:

  public function __construct($uuid, $region, array $configuration = [], array $third_party_settings = []) {
#59.6: Please add explanatory array keys for the data providers, explaining what each is testing.

Do you mean something like?

-   $data[] = [
+   $data['Verify non-existing key returns NULL'] = [
      'Chotchkie\'s',
      'non_existing_key',
      NULL,
    ];
tim.plunkett’s picture

(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)

chris burge’s picture

I understand the constructor issue now.

Adding a ::create() method might be the only option to achieve this, but I'm open to ideas.

I don't have a better solution. Is there an example out there in core to use for a reference for this use case?

tim.plunkett’s picture

\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.

chris burge’s picture

If we wanted to switch to a private constructor, would that transition look something like this?

  • Drupal 9.0 - no changes
  • Drupal 9.1 - constructor is still public and static ::create() method is added; instantiating SectionComponent object directly is supported but deprecated
  • Drupal 10.0 - constructor becomes private and static ::create() method becomes the only way to instantiate a SectionComponent object

A module that is compatible with both D9 and D10 would use the ::create() method.

tim.plunkett’s picture

Yep 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 🤢

chris burge’s picture

I'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:

  // Drupal 9.0
  public function __construct($uuid, $region, array $configuration = [], array $additional = []) {
    $this->uuid = $uuid;
    $this->region = $region;
    $this->configuration = $configuration;
    $this->additional = $additional;
  }
      
  // Drupal 9.1
  public function __construct($uuid, $region, array $configuration = [], array $additional = [], array $third_party_settings = []) {
    $this->uuid = $uuid;
    $this->region = $region;
    $this->configuration = $configuration;
    $this->additional = $additional;
    if ($additional) {
      @trigger_error('Setting additional properties is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Additional component properties should set via ::setThirdPartySetting(). See https://www.drupal.org/node/XXX', E_USER_DEPRECATED);
    }
    $this->thirdPartySettings = $third_party_settings;
  }

  // Drupal 10.0
  public function __construct($uuid, $region, array $configuration = [], array $additional = [], array $third_party_settings = []) {
    $this->uuid = $uuid;
    $this->region = $region;
    $this->configuration = $configuration;
    if ($third_party_settings) {
      $this->thirdPartySettings = $third_party_settings;
      @trigger_error('Passing third party settings as the fourth argument to ' . __METHOD__ . ' is deprecated in drupal:10.0.0 and will throw a fatal error in drupal:11.0.0. Pass third party settings as the third argument. See https://www.drupal.org/node/XXX', E_USER_DEPRECATED);
      if ($additional) {
        // Do something here or just ignore $additional?
      }
    }
    elseif ($additional) {
      $this->thirdPartySettings = $additional;
    }
  }

  // Drupal 11.0
  public function __construct($uuid, $region, array $configuration = [], array $third_party_settings = []) {
    $this->uuid = $uuid;
    $this->region = $region;
    $this->configuration = $configuration;
    $this->thirdPartySettings = $third_party_settings;
  }
chris burge’s picture

Status: Needs work » Needs review
StatusFileSize
new19.72 KB
new9.12 KB

Updated patch, along with interdiff, is attached. All changes from #59 and #61 have been made.

I ended up going the backtrace route. The SectionComponent object 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.]

chris burge’s picture

Re the test results for #67, we're seeing a bunch of deprecation notices because I didn't replace new SectionComponent with SectionComponent::create outside of the existing work of this issue. I figured I see what feedback there is on the current approach first.

geek-merlin’s picture

Looks good!

I'm a bit concerned though about the performance and memory footprint 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...

chris burge’s picture

@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 SectionComponent object was created for each component for a given Layout Builder-enabled entity.

chris burge’s picture

Assigned: chris burge » Unassigned
chris burge’s picture

Adding related issue: #3159712: SectionComponent should provide an unset() method. Modules using $additional can't clean up after themselves without an unset() method provided by SectionComponent. This will be needed once $additional is deprecated by this issue.

segovia94’s picture

I 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.

chris burge’s picture

Assigned: Unassigned » chris burge
Status: Needs review » Needs work

@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 of get() and set(). This means the tools are there for an upgrade path from $additional to third party settings. Once $additional is removed, we'll no longer have a need for the get() and set() methods, so they can be deprecated, too.

Remaining tasks:

chris burge’s picture

Assigned: chris burge » Unassigned
Status: Needs work » Needs review
StatusFileSize
new49.1 KB
new34.15 KB

Updated 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.

tim.plunkett’s picture

Issue summary: View changes
Status: Needs review » Needs work

Consider this sign-off as the relevant subsystem maintainer.

  1. +++ b/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php
    @@ -436,7 +436,7 @@ class LayoutBuilderEntityViewDisplay extends BaseEntityViewDisplay implements La
    +      $new_component = (SectionComponent::create(\Drupal::service('uuid')->generate(), $region, $configuration));
    

    Nit: all of these leading parens were because of calling a method on the object created by new and that is no longer relevant and they should be removed.

  2. +++ b/core/modules/layout_builder/src/SectionComponent.php
    @@ -309,12 +377,71 @@ class SectionComponent {
         return (new static(
    

    Regardless of the fact that this could be used even after it is private, let's switch this to explicitly use ::create() as well.

  3. +++ b/core/modules/layout_builder/tests/src/Unit/SectionComponentTest.php
    @@ -20,6 +21,37 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
     class SectionComponentTest extends UnitTestCase {
    

    One thing that is missing are explicit tests for each of the @trigger_error calls

chris burge’s picture

Status: Needs work » Needs review
StatusFileSize
new51.56 KB
new12.39 KB

Updated patch attached with the following change:

  • 76.1 - The extra parentheses have been removed.
  • 76.2 - Maybe handle this with a D10 comment? The :::create() method cannot accept the $additional parameter. Existing code that calls ::fromArray() and passes an 'additional' value would not execute as expected because ::create() cannot provide that data to the constructor.
  • 76.3 - Test coverage is added.
  • Added some additional comments that I missed earlier.

Status: Needs review » Needs work

The last submitted patch, 77: 3015152-77.patch, failed testing. View results

chris burge’s picture

Status: Needs work » Needs review
StatusFileSize
new53.24 KB
new2.18 KB

Rerolled patch addresses new committed code that's causing deprecation notices. It also adds a comment to address 76.2.

chris burge’s picture

Status: Needs review » Needs work

Per #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.

chris burge’s picture

Status: Needs work » Needs review
StatusFileSize
new53.53 KB
new2.13 KB

Updated patch attached.

chris burge’s picture

StatusFileSize
new53.53 KB
new620 bytes

Updated patch with typo fix.

neslee canil pinto’s picture

Status: Needs review » Reviewed & tested by the community

#82 worked for me along with one of my modules to support third party settings. Moving it to RTBC

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 82: 3015152-82.patch, failed testing. View results

chris burge’s picture

Status: Needs work » Reviewed & tested by the community

Test failure was an intermittent and unrelated failure of Drupal\Tests\ckeditor\FunctionalJavascript\CKEditorIntegrationTest. Setting back to RTBC.

akalam’s picture

StatusFileSize
new51.93 KB

#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

chris burge’s picture

Re #86, this issue is targeted for 9.1.x, not 9.0.x. New features cannot go in 9.0.x.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 86: 3015152-86.patch, failed testing. View results

geek-merlin’s picture

Status: Needs work » Reviewed & tested by the community

So current RTBC patch is #82.

tim.plunkett’s picture

StatusFileSize
new53.39 KB

Reuploading 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.

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/layout_builder/src/SectionComponent.php
@@ -309,12 +382,75 @@ public function toArray() {
+    // Ensure expected array keys are present.
+    $component += [
+      'uuid' => '',
+      'region' => [],
+      'configuration' => [],
+      // @todo Remove below key/value when the drupal:10.0.x branch is opened.
+      // @see https://www.drupal.org/project/drupal/issues/3160644
+      'additional' => [],
+      'third_party_settings' => [],
+    ];
+    // @todo Use create() method when the drupal:10.0.x branch is opened.

So 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.

chris burge’s picture

So this is called heavily on deserializing from stored values in the DB right?

I'm not sure I follow. That code is part of the fromArray() method, which creates a SectionComponent object from an array.

Do we have a plan for removing saved values in the additional key from stored overrides?

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.

When we get to D10, will those just be silently ignored?

That seems reasonable.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Note 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.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

I think maybe we can do a little bit more to cleanup.

  1. +++ b/core/modules/layout_builder/config/schema/layout_builder.schema.yml
    @@ -52,6 +52,11 @@ layout_builder.component:
         additional:
           type: ignore
           label: 'Additional data'
    

    We can deprecate this now. See https://www.drupal.org/node/3129881

  2. +++ b/core/modules/layout_builder/src/SectionComponent.php
    @@ -65,13 +81,53 @@ class SectionComponent {
    +    // @todo Remove below conditional when the drupal:10.0.x branch is opened.
    +    // @see https://www.drupal.org/project/drupal/issues/3160644
    +    if (!$instantiated_by_create) {
    +      @trigger_error('Instantiating a SectionComponent object directly is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. SectionComponents should be instantiated using the SectionComponent::create() method instead. See https://www.drupal.org/node/3100177', E_USER_DEPRECATED);
    +    }
    

    This seems icky but pragmatic and will help custom and contrib update. Nice.

  3. +++ b/core/profiles/demo_umami/config/install/core.entity_view_display.node.recipe.full.yml
    @@ -211,6 +220,7 @@ third_party_settings:
                 additional: {  }
    

    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 additional is 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.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

joey-santiago’s picture

We 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

tim.plunkett’s picture

Your 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

hkirsman’s picture

We 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?

szeidler’s picture

Orphaned 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.

fabianx’s picture

+++ b/core/modules/layout_builder/src/SectionComponent.php
@@ -309,12 +382,75 @@ public function toArray() {
+  /**
+   * {@inheritdoc}
+   */
+  public function getThirdPartySetting($provider, $key, $default = NULL) {
+    return isset($this->thirdPartySettings[$provider][$key]) ? $this->thirdPartySettings[$provider][$key] : $default;
+  }

Not 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

andypost’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/layout_builder/src/SectionComponent.php
    @@ -65,13 +81,53 @@ class SectionComponent {
    +   * @param string $uuid
    ...
    +   * @param string $region
    ...
    +  public static function create($uuid, $region, array $configuration = [], array $third_party_settings = []) {
    

    uuid and region needs string types declared

  2. +++ b/core/modules/layout_builder/src/SectionComponent.php
    @@ -309,12 +382,75 @@ public function toArray() {
    +      'uuid' => '',
    +      'region' => [],
    

    region is the string type (not array)

mxh’s picture

Status: Needs work » Needs review
StatusFileSize
new55.52 KB
new6.73 KB

Addressing #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.

tim.plunkett’s picture

Status: Needs review » Needs work

As 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.

anmolgoyal74’s picture

StatusFileSize
new56.07 KB
new475 bytes

Added words to the dictionary.txt file.

anmolgoyal74’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 105: 3015152-tps-105.patch, failed testing. View results

mxh’s picture

Looks 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.full fails in Demo_umami.Drupal\Tests\demo_umami\Functional\DemoUmamiProfileTest, it shouldn't have been touched within this patch? I added the third_party_settings: { } to layout_builder_defaults_test/config/install/core.entity_view_display.entity_test.bundle_with_extra_fields.default.yml though.

mxh’s picture

StatusFileSize
new55.91 KB
new698 bytes

Just 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.

mxh’s picture

Status: Needs work » Needs review
mxh’s picture

StatusFileSize
new55.94 KB
new2.7 KB
new9.29 KB

Replaced deprectated @expectedDeprecation annotation (the inception of deprecations...).

The last submitted patch, 109: 3015152-tps-109.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 111: 3015152-tps-111.patch, failed testing. View results

mxh’s picture

Status: Needs work » Needs review
StatusFileSize
new54.98 KB
new5.35 KB
new4.92 KB

I 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 the deprecated key in the config schema without breaking all the tests (see test results from #105). Alternatively, the config schema could get a @todo comment in the D9 patch.

tim.plunkett’s picture

Sorry 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.full

mxh’s picture

StatusFileSize
new58.18 KB
new3.2 KB

Thanks 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.

mxh’s picture

At the current state of this patch, there is no form handling regards TPS inlcuded (see ConfigureBlockFormBase::submitForm and 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. Should SectionComponent instances also have a way of auto-including TPS form values?

Another thing that's kind of weird is that SectionComponent implements ThirdPartySettingsInterface from the Drupal\Core\Config\Entity namespace, but SectionComponent is not part of the entity system.

anybody’s picture

Issue summary: View changes
anybody’s picture

Hi @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?

mxh’s picture

Hi @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 Section class already includes TPS officially in core, so it's probably not a problem to also include TPS for SectionComponent.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

anybody’s picture

Status: Needs review » Needs work

Thank you @mxh, so I will change status to Needs work. Do we have to add any tags for that decision?

tim.plunkett’s picture

Status: Needs work » Needs review

ThirdPartySettingsInterface is 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.

segovia94’s picture

StatusFileSize
new58.18 KB
new7.1 KB

Re-roll against 9.3.x

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

hswong3i made their first commit to this issue’s fork.

feng-shui’s picture

StatusFileSize
new58.12 KB

Re-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.

anybody’s picture

@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.

thiagomoraesp’s picture

Patch from #124 failed to apply on my 9.3.x, anyone has any other patch that works on 9.3.x?

feng-shui’s picture

@thiagomoraesp #128 is a reroll against 9.3, did you try it?

thiagomoraesp’s picture

@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.

anybody’s picture

Added 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?

anybody’s picture

Issue summary: View changes
anybody’s picture

Issue summary: View changes
heddn’s picture

I 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.

heddn’s picture

Status: Needs review » Needs work

There's also still quite a few references to $additional in the code base. And we should open a follow-up to component_library (if it doesn't exist), to swap out $additional for 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.

heddn’s picture

+++ b/core/modules/layout_builder/src/SectionComponent.php
@@ -65,13 +81,53 @@ class SectionComponent {
+  public static function create(string $uuid, string $region, array $configuration = [], array $third_party_settings = []) {

I not fully convinced this will help with BC. We can deprecate on __construct if anything is passed to $additional. Then entirely remove $additional in 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?

heddn’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record updates
StatusFileSize
new38.43 KB
new27.85 KB

There 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 that DefaultsSectionStorageTest::providerTestAccess was formatted incorrectly for the config schema validation.

I also updated the CR, so cleaning up tags.

heddn’s picture

Another 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.

  1. +++ b/core/modules/layout_builder/src/SectionComponent.php
    @@ -52,9 +53,24 @@ class SectionComponent {
    +   * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0.
    

    Oops, I missed a version adjustment here.

  2. +++ b/core/modules/layout_builder/src/SectionComponent.php
    @@ -99,6 +126,12 @@ public function toRenderArray(array $contexts = [], $in_preview = FALSE) {
    +   * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0.
    

    This version should also get updated.

  3. +++ b/core/modules/layout_builder/src/SectionComponent.php
    @@ -309,12 +353,75 @@ public function toArray() {
    +    return isset($this->thirdPartySettings[$provider][$key]) ? $this->thirdPartySettings[$provider][$key] : $default;
    

    return $this->thirdPartySettings[$provider][$key] ?? $default;

  4. +++ b/core/modules/layout_builder/src/SectionComponent.php
    @@ -309,12 +353,75 @@ public function toArray() {
    +    return isset($this->thirdPartySettings[$provider]) ? $this->thirdPartySettings[$provider] : [];
    

    return $this->thirdPartySettings[$provider] ?? [];

Status: Needs review » Needs work

The last submitted patch, 139: 3015152-139.patch, failed testing. View results

heddn’s picture

Status: Needs work » Needs review
StatusFileSize
new2.85 KB
new27.46 KB

Last test failures were random js test failures. Otherwise, it was green. Here we fix a few self review nits (mentioned in #141).

larowlan’s picture

This looks good, like the pivot away from ::create

  1. +++ b/core/modules/layout_builder/layout_builder.post_update.php
    @@ -67,6 +67,13 @@ function layout_builder_post_update_section_storage_context_mapping(&$sandbox =
    +function layout_builder_post_update_component_third_party_settings_schema() {
    +  // Empty post-update hook.
    +}
    

    shouldn't this load and resave any view display that is LB enabled so the new third_party_settings keys are added?

  2. +++ b/core/modules/layout_builder/src/SectionComponent.php
    @@ -52,9 +53,24 @@ class SectionComponent {
    +   * @deprecated in drupal:9.4.0 and is removed from drupal:11.0.0.
    

    I think we can still target 10.0.0 for removals

  3. +++ b/core/modules/layout_builder/src/SectionComponent.php
    @@ -52,9 +53,24 @@ class SectionComponent {
       protected $additional = [];
    

    Should we make this private, and implement __get and trigger a deprecation if someone accesses it?

  4. +++ b/core/modules/layout_builder/src/SectionComponent.php
    @@ -99,6 +126,12 @@ public function toRenderArray(array $contexts = [], $in_preview = FALSE) {
    +   * @deprecated in drupal:9.4.0 and is removed from drupal:11.0.0.
    +   *   Additional component properties should be gotten
    +   *   via ::setThirdPartySetting().
    +   *
    +   * @see https://www.drupal.org/node/3100177
    

    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

  5. +++ b/core/modules/layout_builder/src/SectionComponent.php
    @@ -120,6 +154,12 @@ public function get($property) {
    @@ -129,6 +169,7 @@ public function set($property, $value) {
    
    @@ -129,6 +169,7 @@ public function set($property, $value) {
         else {
           $this->additional[$property] = $value;
         }
    +    @trigger_error('Setting additional properties is deprecated in drupal:9.4.0 and is removed from drupal:11.0.0. Additional component properties should be set via ::setThirdPartySetting(). See https://www.drupal.org/node/3100177', E_USER_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

  6. +++ b/core/modules/layout_builder/src/SectionComponent.php
    @@ -293,7 +334,10 @@ public function toArray() {
    +      // @todo Remove below key/value when the drupal:10.0.x branch is opened.
    

    This will go into 10.0.x first, so we probably want another branch/patch where that is already gone

  7. +++ b/core/modules/layout_builder/tests/src/Unit/SectionComponentTest.php
    @@ -20,6 +21,38 @@
    +        'Initech' => [
    +          'Bill Lumbergh' => 'TPS reports',
    +          'Milton Waddams' => 'Red Stapler',
    +        ],
    +        'Chotchkies' => [
    +          'flair' => TRUE,
    

    ;-)

  8. +++ b/core/modules/layout_builder/tests/src/Unit/SectionComponentTest.php
    @@ -68,4 +101,217 @@ public function testToRenderArray() {
    +  public function testGetThirdPartySettings($provider, $expected) {
    

    let's add a :void while we're here (and the other methods)

  9. +++ b/core/modules/layout_builder/tests/src/Unit/SectionComponentTest.php
    @@ -68,4 +101,217 @@ public function testToRenderArray() {
    +   * Provides test data for ::testGetThirdPartySettings().
    

    I think we still expect a return-type hint and @return docs here (same for other methods)

  10. +++ b/core/modules/layout_builder/tests/src/Unit/SectionComponentTest.php
    @@ -68,4 +101,217 @@ public function testToRenderArray() {
    +    }
    +    else {
    

    micronit: can return early and avoid else

heddn’s picture

StatusFileSize
new12.92 KB
new29.39 KB

Thanks 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

heddn’s picture

StatusFileSize
new1.3 KB
new29.39 KB

Status: Needs review » Needs work

The last submitted patch, 145: 3015152-145.patch, failed testing. View results

heddn’s picture

Status: Needs work » Needs review
StatusFileSize
new4.9 KB
new34.03 KB

Behold, test coverage of the update path and a few other fixes.

larowlan’s picture

This is looking great, nice to see it coming together

  1. +++ b/core/modules/layout_builder/layout_builder.post_update.php
    @@ -67,9 +68,58 @@ function layout_builder_post_update_section_storage_context_mapping(&$sandbox =
    +/**
    + * Clear caches due to config schema addition.
    + */
    +function layout_builder_post_update_component_third_party_settings_schema() {
    +  // Empty post-update hook.
    +}
    

    we don't need this anymore, now we have an actual post update hook, the caches will be cleared

  2. +++ b/core/modules/layout_builder/src/SectionComponent.php
    @@ -52,9 +53,24 @@ class SectionComponent {
       protected $additional = [];
    

    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

tim.plunkett’s picture

SectionComponent has no interface, it is a value object. Had usage of final and/or private been 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

heddn’s picture

StatusFileSize
new7.2 KB
new33.72 KB

Standardized 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

tim bozeman’s picture

Status: Needs review » Reviewed & tested by the community

Fantastic!

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 150: 3015152-150.patch, failed testing. View results

heddn’s picture

Status: Needs work » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 150: 3015152-150.patch, failed testing. View results

chris burge’s picture

Re-queued 3015152-150.patch to check if #155 is an intermittent FunctionalJavascript failure:

Drupal\Tests\quickedit\FunctionalJavascript\LayoutBuilderQuickEditTest

fail: [Other] Line 0 of sites/default/files/simpletest/phpunit-148.xml:
PHPUnit Test failed to complete; Error: PHPUnit 9.5.20 �[44m#StandWith�[0m�[43mUkraine�[0m

Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

Testing Drupal\Tests\quickedit\FunctionalJavascript\LayoutBuilderQuickEditTest
F....                                                               5 / 5 (100%)

Time: 01:46.855, Memory: 4.00 MB

There was 1 failure:

1) Drupal\Tests\quickedit\FunctionalJavascript\LayoutBuilderQuickEditTest::testQuickEditIgnoresDuplicateFields
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
     'node/1/title/en/layout_builder-default-non_component-5426f50c51044a2daaab1ca8b2a4095a6c709a616f9aa8a171c75eb8e13178c1' => 'inactive'
+    'node/1/body/en/layout_builder-default-0-cd90a19a_81c4_4f4f_8f23_af63b2be7a3d-1-5426f50c51044a2daaab1ca8b2a4095a6c709a616f9aa8a171c75eb8e13178c1' => 'inactive'
 )
heddn’s picture

Status: Needs work » Reviewed & tested by the community
abarrio’s picture

Any news on this?
It would be ok to have it on next release in order to extend functionalities.

ravi.shankar’s picture

StatusFileSize
new3.27 KB
new33.74 KB

Added reroll of patch #150 for Drupal 10.0.x, as this will go to Drupal 10 also.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 159: 3015152-159.patch, failed testing. View results

anybody’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 159: 3015152-159.patch, failed testing. View results

anybody’s picture

#150 and #159 both fail with the following strange error:

Drupal\Tests\layout_builder\Functional\Update\LayoutBuilderSectionComponentUpdatePathTest::testRunUpdates
require(compress.zlib:///var/www/html/core/modules/layout_builder/tests/src/Functional/Update/../../../../../system/tests/fixtures/update/drupal-9.3.0.bare.standard.php.gz): Failed to open stream: operation failed

ravi.shankar’s picture

StatusFileSize
new40.57 KB

Added reroll of patch #150 on Drupal 9.5.x. as It's not getting applied.

ravi.shankar’s picture

StatusFileSize
new33.72 KB

Added 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.

anybody’s picture

@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)

ravi.shankar’s picture

StatusFileSize
new1.92 KB

Added reroll diff of patch #150 and #165.

anybody’s picture

Status: Needs work » Reviewed & tested by the community

Thanks, 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!!

The last submitted patch, 164: 3015152-164.patch, failed testing. View results

anybody’s picture

hswong3i’s picture

StatusFileSize
new0 bytes
hswong3i’s picture

StatusFileSize
new33.61 KB
hswong3i’s picture

StatusFileSize
new28.76 KB
grevil’s picture

@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?

anybody’s picture

RTBC is still for #165.

anybody’s picture

@ravi.shankar sorry, reading the patch one more time I saw these lines:

@deprecated in drupal:9.4.0 and is removed from drupal:11.0.0.

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! :)

anybody’s picture

quietone’s picture

Version: 9.5.x-dev » 10.1.x-dev
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Only 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.

vsujeetkumar’s picture

Status: Needs work » Needs review
StatusFileSize
new33.73 KB

Re-roll patch created for 10.1.x from #165, Please have a look.

Status: Needs review » Needs work

The last submitted patch, 180: 3015152-180.patch, failed testing. View results

Ankit.Gupta’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new29.76 KB

Reroll the patch #180 with Drupal 10.1.x

amarlata’s picture

StatusFileSize
new29.76 KB

Fixed coding standard.

Ratan Priya’s picture

StatusFileSize
new811 bytes
new29.76 KB

Fixed failed custom command for patch #183.

Status: Needs review » Needs work

The last submitted patch, 184: 3015152-184.patch, failed testing. View results

Webbeh’s picture

Status: Needs work » Needs review

It 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).

larowlan’s picture

Looked 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.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new145 bytes

The 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.

amjad1233’s picture

StatusFileSize
new29.76 KB
new157 bytes

Patch re-rolled for Drupal 9.5.3

szeidler’s picture

Something went wrong in some of the recent of the patches for 9.x. The patch adds use for classes that are declared already since a few Drupal core releases.

use Drupal\Core\Config\Entity\ConfigEntityUpdater;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\layout_builder\Entity\LayoutEntityDisplayInterface;

use Drupal\Core\Config\Entity\ConfigEntityUpdater;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\layout_builder\Entity\LayoutEntityDisplayInterface;
use Drupal\layout_builder\SectionComponent;
amjad1233’s picture

StatusFileSize
new29.77 KB

Another stab at re-roll...

Against 9.5.x

heddn’s picture

Status: Needs work » Needs review
StatusFileSize
new29.71 KB

Against 10.1.x. Had conflicts on dictionary.txt

Status: Needs review » Needs work

The last submitted patch, 192: 3015152-192.patch, failed testing. View results

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

luke.leber’s picture

I 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 $additional is not something to take lightly for huge sites.

Here's a (hopefully, exaggerated) persona that might be able to help...

As a site owner with hundreds of content editors making dozens of updates to layout overrides per minute, and with 50,000+ layout overrides and 1,000,000+ revisions, the migration from additional properties to third party settings should incur no downtime or editorial confusion while the migration runs. Assuming the migration takes several hours, losing database connectivity or infrastructure resource problems should not cause a "we need to roll back" condition.

vipin.j’s picture

Version: 11.x-dev » 10.1.x-dev
StatusFileSize
new29.82 KB

Patch #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.

heddn’s picture

Re #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.module adds some $additional items, I would expect/hope that it would handle the deprecation.

heddn’s picture

Version: 10.1.x-dev » 11.x-dev
Status: Needs work » Needs review
StatusFileSize
new29.77 KB
new5.46 KB

Re-roll for 11.x and fixing version strings in deprecations.

chris burge’s picture

Re #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 $additional to 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.

Status: Needs review » Needs work

The last submitted patch, 198: 3015152-198.patch, failed testing. View results

heddn’s picture

Status: Needs work » Needs review
StatusFileSize
new29.78 KB

No interdiff on the re-roll. The only conflicts where in cspell and were trivial to resolve manually.

smustgrave’s picture

Status: Needs review » Needs work

CC failures, but #198 appeared to have some test failures.

pyrello made their first commit to this issue’s fork.

pyrello’s picture

I 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.

milos.kroulik’s picture

Just 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).

luke.leber’s picture

I 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

actuallyam’s picture

Could 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:

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)
capysara’s picture

@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.

jjpost’s picture

StatusFileSize
new31.03 KB

Patch of the latest MR like capysara suggested

rahaf albawab’s picture

StatusFileSize
new30.16 KB

This is a reroll of #211 for 10.3.x

carolpettirossi’s picture

Applying this patch from #213 was helpful in make layout_builder_styles work properly when upgrading to 10.3.1.

I was getting

Deprecated function: Creation of dynamic property Drupal\layout_builder\SectionComponent::$thirdPartySettings is deprecated in Drupal\Component\Serialization\PhpSerialize::decode() (line 21 of core/lib/Drupal/Component/Serialization/PhpSerialize.php).

and also

Error: Call to a member function getSection() on null in Drupal\layout_builder\Form\ConfigureBlockFormBase->getCurrentSection() (line 341 of /var/www/web/core/modules/layout_builder/src/Form/ConfigureBlockFormBase.php).

When trying to create a new block or edit an existing block.

carolpettirossi’s picture

One 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)

carolpettirossi’s picture

Drupal 10.3 and PHP 8.2 compatibility MR has been created: MR 8724. Can someone please review?

papagrande’s picture

Issue tags: +PHP 8.2

acbramley changed the visibility of the branch 10.2.x to hidden.

acbramley changed the visibility of the branch 11.x to hidden.

acbramley’s picture

We 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?

flyke’s picture

None of the branches (diff files) or patches seem to apply to Drupal 11.0.5

flyke’s picture

StatusFileSize
new2.51 MB

I 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 ?

flyke’s picture

flyke’s picture

StatusFileSize
new29.72 KB

Update, 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.diff file
- create a patch
git diff > 3015152-225.patch
Tested and it works on 11.0.5

acbramley changed the visibility of the branch drupal-3015152-3015152-support-third-party-11.x to hidden.

acbramley changed the visibility of the branch drupal-3015152 to hidden.

acbramley changed the visibility of the branch 3015152-support-third-party to hidden.

acbramley changed the visibility of the branch 3015152-support-third-party-9.4.x to hidden.

acbramley changed the visibility of the branch 3015152-support-third-party-10.2.x to hidden.

acbramley’s picture

Attempting 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.

acbramley changed the visibility of the branch 3015152-support-third-party-10.3.x-php8.2 to hidden.

acbramley’s picture

Status: Needs work » Needs review
heddn’s picture

Update tests added and are green now. IS seems up to date. Ready for review.

flyke’s picture

If 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 1264
Strangely, 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

flyke’s picture

StatusFileSize
new214.34 KB

In 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:

function _fix_sections_d11() {
  // Get all Layoutbuilder nodes.
  $nids = \Drupal::entityQuery('node')->accessCheck(FALSE)->condition('layout_builder__layout', '', '<>')->execute();
  $nodes = Node::loadMultiple($nids);

  $count = count($nodes);
  $node_index = 0;

  echo "Processing $count nodes to get all sections\n";

  // Loop all Layout Builder nodes.
  foreach ($nodes as $node) {
    $resave_node = FALSE;
    $node_index++;
    $section_index = 0;
    $nid = $node->id();

    // Get all sections for the current node.
    /** @var \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface $layout */
    $layout = $node->get(OverridesSectionStorage::FIELD_NAME);
    /** @var \Drupal\layout_builder\Section[] $sections */
    $sections = $layout->getSections();
    foreach ($sections as &$section) {

      $section_index++;
      $component_index = 0;

      // Get all components for the current section.
      $components = $section->getComponents();
      foreach ($components as $component) {

        $component_index++;

        echo "- Processing node $nid - section $section_index - component $component_index:";

        // Get all variables of the current component.
        $object_vars = get_object_vars($component);

        // Validate: If there are no variables, then there certainly will not be any legacyAdditionalModuleKey variable.
        if (empty($object_vars)) {
          echo " ----- DONE! it does NOT contain legacyAdditionalModuleKey\n";
          continue;
        }

        // We cannot simply use isset() because that does not work with binary strings like $object_vars["\x00*\x00legacyAdditionalModuleKey"].
        // Instead, convert to json string and see if that contains legacyAdditionalModuleKey.
        $json = json_encode($object_vars);
        // Validate.
        if (!str_contains($json, '\u0000*\u0000legacyAdditionalModuleKey')) {
          echo " ----- DONE! it does NOT contain legacyAdditionalModuleKey\n";
          continue;
        }

        // If we are here, the $component has a legacyAdditionalModuleKey variable.
        // To fix it, we convert the object to array and then create object again from that array.
        // This gets rid of the legacyAdditionalModuleKey!.
        echo " ----- It DOES contain legacyAdditionalModuleKey !\n";
       $component_array = $component->toArray();
       $new_component = $component->fromArray($component_array);
       $section->insertAfterComponent($component->getUuid(), $new_component);
       $section->removeComponent($component->getUuid());
       $resave_node = TRUE;
       echo "-- Fixed the section component !\n";
      }
      if ($resave_node) {
        $node->save();
      }
    }
  }
}

acbramley’s picture

@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.

flyke’s picture

A 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.

acbramley’s picture

Issue summary: View changes

Thanks 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.

acbramley changed the visibility of the branch 3015152-support-third-party-10.3.x to hidden.

flyke’s picture

Hi @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 cr and then drush updb -y but nothing happened, nothing run, and the errors
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 1264
remain

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.

acbramley’s picture

Hey @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.

luke.leber’s picture

I 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. 🤞

acbramley’s picture

Feel 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.

luke.leber’s picture

Feel 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

<?php

namespace Drupal\psu_layout_builder;

use Drupal\Core\Database\Connection;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\layout_builder\Section;
use Drupal\layout_builder\SectionComponent;

/**
 * Helper to facilitate 'additional' to 'third_party_settings' migration.
 */
class SectionComponentTPS {

  /**
   * Service constructor.
   *
   * @param \Drupal\Core\Database\Connection $database
   *   The database connection service.
   */
  public function __construct(
    protected Connection $database
  ) { }

  /**
   * Migrates 'additional' to 'third_party_settings' for the provided table.
   *
   * @param string $table
   *   The database table to migrate.
   * @param array $sandbox
   *   The post-update sandbox.
   *
   * @throws \Exception
   *   😱 God help you if this happens.
   */
  public function migrate(string $table, array &$sandbox, $sections_per_batch = 10000) {
    if (!isset($sandbox['total'])) {
      $query = $this->database->select($table);
      $sandbox['total'] = $query->countQuery()->execute()->fetchObject()->expression;
      $sandbox['current'] = 0;
      if (empty($sandbox['total'])) {
        $sandbox['#finished'] = 1;
        return NULL;
      }
    }

    $query = $this->database
      ->select($table, 'layout')
      ->fields('layout', ['bundle', 'entity_id', 'revision_id', 'langcode', 'delta', 'layout_builder__layout_section'])
      ->range($sandbox['current'], $sections_per_batch);

    $rows = $query->execute()->fetchAll(\PDO::FETCH_ASSOC);
    if (empty($rows)) {
      $sandbox['#finished'] = 1;
      return;
    }
    else {

      // Combine all update queries into a single upsert for performance.
      $upsert = $this->database->upsert($table)
        ->fields(['bundle', 'entity_id', 'revision_id', 'langcode', 'delta', 'layout_builder__layout_section'])
        ->key('revision_id');

      foreach ($rows as $row) {
        /** @var \Drupal\layout_builder\Section $section */
        $section = unserialize($row['layout_builder__layout_section'], ['allowed_classes' => [Section::class, SectionComponent::class]]);
        foreach ($section->getComponents() as $component) {
          // Set might be deprecated, but it's hella efficient.
          // Don't run this code on Drupal 12, eh?
          $component->set('thirdPartySettings', $component->get('additional') ?: []);
          $component->set('additional', []);
        }
        $row['layout_builder__layout_section'] = serialize($section);
        $sandbox['current']++;
        $upsert->values($row);
      }

      $upsert->execute();
    }

    if ($sandbox['current'] >= $sandbox['total']) {
      $sandbox['#finished'] = 1;
    }
    else {
      $sandbox['#finished'] = ($sandbox['current'] / $sandbox['total']);
    }
    return new TranslatableMarkup('@count of @total' . ' layout sections processed.', [
      '@count' => $sandbox['current'],
      '@total' => $sandbox['total'],
    ]);
  }

}

Service configuration boilerplate

services:
  Drupal\psu_layout_builder\SectionComponentTPS:
    class: Drupal\psu_layout_builder\SectionComponentTPS
    autowire: true

Sample post update hooks for *one* entity type

/**
 * Migrate 'additional' to 'third_party_settings' for nodes.
 */
function psu_layout_builder_post_update_tps_nodes(array &$sandbox) {
  return \Drupal::service(SectionComponentTPS::class)->migrate('node__layout_builder__layout', $sandbox, 10000);
}

/**
 * Migrate 'additional' to 'third_party_settings' for node revisions.
 */
function psu_layout_builder_post_update_tps_node_revisions(array &$sandbox) {
  return \Drupal::service(SectionComponentTPS::class)->migrate('node_revision__layout_builder__layout', $sandbox, 10000);
}

Let's do this thing @ 10,000 records per batch.

www-data@9218f372c877:~/html$ time drush updb
 -------------------- -------------------- ------------- ---------------------- 
  Module               Update ID            Type          Description           
 -------------------- -------------------- ------------- ---------------------- 
  psu_layout_builder   tps_node_revisions   post-update   Migrate 'additional'  
                                                          to                    
                                                          'third_party_setting  
                                                          s' for node           
                                                          revisions.            
  psu_layout_builder   tps_nodes            post-update   Migrate 'additional'  
                                                          to                    
                                                          'third_party_setting  
                                                          s' for nodes.         
 -------------------- -------------------- ------------- ---------------------- 


 Do you wish to run the specified pending updates? (yes/no) [yes]:
 > 

>  [notice] Update started: psu_layout_builder_post_update_tps_node_revisions
>  [notice] 10000 of 208192 layout sections processed.
>  [notice] 20000 of 208192 layout sections processed.
>  [notice] 30000 of 208192 layout sections processed.
>  [notice] 40000 of 208192 layout sections processed.
>  [notice] 50000 of 208192 layout sections processed.
>  [notice] 60000 of 208192 layout sections processed.
>  [notice] 70000 of 208192 layout sections processed.
>  [notice] 80000 of 208192 layout sections processed.
>  [notice] 90000 of 208192 layout sections processed.
>  [notice] 100000 of 208192 layout sections processed.
>  [notice] 110000 of 208192 layout sections processed.
>  [notice] 120000 of 208192 layout sections processed.
>  [notice] 130000 of 208192 layout sections processed.
>  [notice] 140000 of 208192 layout sections processed.
>  [notice] 150000 of 208192 layout sections processed.
>  [notice] 160000 of 208192 layout sections processed.
>  [notice] 170000 of 208192 layout sections processed.
>  [notice] 180000 of 208192 layout sections processed.
>  [notice] 190000 of 208192 layout sections processed.
>  [notice] 200000 of 208192 layout sections processed.
>  [notice] 208192 of 208192 layout sections processed.
>  [notice] Update completed: psu_layout_builder_post_update_tps_node_revisions
>  [notice] Update started: psu_layout_builder_post_update_tps_nodes
>  [notice] 6082 of 6082 layout sections processed.
>  [notice] Update completed: psu_layout_builder_post_update_tps_nodes
 [success] Finished performing updates.

real    0m15.490s
user    0m7.965s
sys     0m0.749s

15 seconds to churn through over 210,000 records seems agreeable to me!

flyke’s picture

StatusFileSize
new310.5 KB

Not 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.

smustgrave’s picture

Status: Needs review » Needs work

Appears 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!

stomusic made their first commit to this issue’s fork.

stomusic’s picture

StatusFileSize
new41.69 KB

Reroll for 11.x

acbramley’s picture

Status: Needs work » Needs review

@smustgrave anything in particular you're unsure of in the CR? I've modified the title slightly and updated versions

acbramley’s picture

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

I think the CR reads fine now and cleared it up for me. Fingers crossed.

bkosborne’s picture

Status: Reviewed & tested by the community » Needs work

Thanks 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 additional at 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.

acbramley’s picture

Status: Needs work » Needs review

@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.

heddn’s picture

re #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.

chris burge’s picture

As 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 additional property will have until D12 to address the deprecation.

luke.leber’s picture

I 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.

acbramley’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the valuable feedback everyone, I think this can go back to RTBC then.

heddn’s picture

#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.

luke.leber’s picture

Atlanta 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 😥

nod_’s picture

Since there are upgrade path concerns, tagging for RM review

flyke’s picture

I 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.

catch’s picture

Status: Reviewed & tested by the community » Needs work

Just 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.

thiagomoraesp’s picture

Hello 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

flyke’s picture

The current MR does not apply to D11.2.0 by the way, in case people are wondering.

acbramley’s picture

Status: Needs work » Needs review

I'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

acbramley’s picture

Status: Needs review » Needs work

I 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.

xjm’s picture

Title: Support third party settings for components within a section » Support third-party settings for components within a section

 

hmdnawaz’s picture

StatusFileSize
new19.58 KB

patch for 11.2.2 without tests

hmdnawaz’s picture

StatusFileSize
new23.56 KB
acbramley’s picture

Status: Needs work » Needs review

I'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_settings key 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.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The 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.

acbramley’s picture

Status: Needs work » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The 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.

acbramley’s picture

Status: Needs work » Needs review
carolpettirossi’s picture

I 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.

carolpettirossi’s picture

StatusFileSize
new9.71 KB

Sorry, my bad, the correct patch is attached.

carolpettirossi’s picture

For 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 1264

Here's a patch to solve that Deprecated notice.

acbramley’s picture

@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.

vensires made their first commit to this issue’s fork.

vensires’s picture

I 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.

vensires’s picture

Also adding as hidden the patch for v10.5.x I previously forgot.

vensires changed the visibility of the branch 10.3.x to hidden.

vensires changed the visibility of the branch 10.6.x to hidden.

vensires changed the visibility of the branch 10.5.x to hidden.

vensires changed the visibility of the branch 10.4.x to hidden.

vensires changed the visibility of the branch 3015152-support_third_party_settings_for_components_within_a_section-10.x to hidden.

vensires’s picture

Previous patch for 10.5.x failed when using composer patches v2.0. Rerolled for 10.6.x.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The 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.

acbramley’s picture

Status: Needs work » Needs review

All the new MRs and patches tripped the bot.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The 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.

acbramley’s picture

Status: Needs work » Needs review
Issue tags: +no-needs-review-bot

Bot is trying to apply an MR that has been closed.

mkdok’s picture

StatusFileSize
new16.95 KB

Patch for 11.3.2

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

smustgrave’s picture

Status: Needs review » Needs work

MR mentions removing some code with 12.x opens. Main is open so should that just be made?

acbramley’s picture

Status: Needs work » Needs review

Tidied 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 additional usage.

acbramley’s picture

Needs 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.