Change record status: 
Project: 
Introduced in branch: 
8.7.x
Introduced in version: 
8.7.0
Description: 

As of #2942661: Sections should have third-party settings, it is possible for layout sections to have arbitrary third-party settings attached to them. These settings are treated exactly the same way as third-party settings on config entities, and can be manipulated with the methods defined in Drupal\Core\Config\Entity\ThirdPartySettingsInterface.

For example, assuming Layout Builder is enabled, and the "Full content" node display has layout enabled and at least one layout section, you can do this:

<?php

use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;

$section = LayoutBuilderEntityViewDisplay::load('node.page.full')->getSection(0);

$setting = $section->getThirdPartySetting('my_module', 'my_setting');
$section->setThirdPartySetting('my_module', 'my_setting', 'some value');
$section->unsetThirdPartySetting('my_module', 'some_dead_setting');

The third party settings will be preserved when the section is converted to an array (for example, when exporting layout configuration).

Impacts: 
Module developers

Comments

fabianx’s picture

For within Forms, use: getCurrentSection()

e.g. instead of:

  $config = $formState->getFormObject()->getLayout()->getConfiguration();

use

  $config = $formState->getFormObject()->getCurrentSection()->getThirdPartySettings("my_module");