Change record status: 
Project: 
Introduced in branch: 
11.x
Introduced in version: 
11.2.0
Description: 

This change further extends the improvements made in https://www.drupal.org/node/3035096 by allowing individual components within a section to have optional third-party settings declared within their declaration. This allows modules like https://drupal.org/project/block_class and https://drupal.org/project/field_formatter_class a clean way of adding classes to individual components (such as blocks) not just on their parent sections. Without third-party settings, there is no good way for Typed Data configuration schema to exist for these third-party configurations.

As part of this, the additional property of section components is deprecated. Modules storing settings in additional will need to migrate to using third-party settings.

Originally:

function my_module_form_layout_builder_configure_block_alter(array &$form, FormStateInterface $form_state) {
  $component = $form_state->getFormObject()->getCurrentComponent();
  $default_value = $component->get('my_tps_setting')
  $form['settings']['my_tps_setting'] = [
      '#type' => 'textfield',
      '#title' => $this->t('My setting'),
      '#default_value' => $default_value,
    ];
    $form['#submit'][] = '_my_module_tps_submit';
}

function _my_module_tps_submit(array &$form, FormStateInterface $form_state) {
    $component = $form_state->getFormObject()->getCurrentComponent();
    $my_tps_setting = $form_state->getValue(['settings', 'my_tps_setting']);
    $component->set('my_tps_setting', $my_tps_setting);
}

Now:

function my_module_form_layout_builder_configure_block_alter(array &$form, FormStateInterface $form_state) {
  $component = $form_state->getFormObject()->getCurrentComponent();
  $default_value = $component->getThirdPartySetting('my_module', 'my_tps_setting')
  $form['settings']['my_tps_setting'] = [
      '#type' => 'textfield',
      '#title' => $this->t('My setting'),
      '#default_value' => $default_value,
    ];
    $form['#submit'][] = '_my_module_tps_submit';
}

function _my_module_tps_submit(array &$form, FormStateInterface $form_state) {
    $component = $form_state->getFormObject()->getCurrentComponent();
    $my_tps_settings = $form_state->getValue(['settings', 'my_tps_setting']);
    $component->setThirdPartySetting('my_module', 'my_tps_setting', $my_tps_settings);
}

To write an upgrade path for additional to third_party_settings data, there are a few options. If you want to do the upgrade in a hook update, see comment on an approach.

Impacts: 
Module developers
Themers