public function FieldLayoutEntityDisplayTrait::setLayoutId in Drupal 10
Same name and namespace in other branches
- 8 core/modules/field_layout/src/Entity/FieldLayoutEntityDisplayTrait.php \Drupal\field_layout\Entity\FieldLayoutEntityDisplayTrait::setLayoutId()
- 9 core/modules/field_layout/src/Entity/FieldLayoutEntityDisplayTrait.php \Drupal\field_layout\Entity\FieldLayoutEntityDisplayTrait::setLayoutId()
Implements \Drupal\field_layout\Display\EntityDisplayWithLayoutInterface::setLayoutId().
File
- core/
modules/ field_layout/ src/ Entity/ FieldLayoutEntityDisplayTrait.php, line 47
Class
- FieldLayoutEntityDisplayTrait
- Provides shared code for entity displays.
Namespace
Drupal\field_layout\EntityCode
public function setLayoutId($layout_id, array $layout_settings = []) {
if ($this
->getLayoutId() !== $layout_id) {
// @todo Devise a mechanism for mapping old regions to new ones in
// https://www.drupal.org/node/2796877.
$layout_definition = $this
->getLayoutDefinition($layout_id);
$new_region = $layout_definition
->getDefaultRegion();
$layout_regions = $layout_definition
->getRegions();
foreach ($this
->getComponents() as $name => $component) {
if (isset($component['region']) && !isset($layout_regions[$component['region']])) {
$component['region'] = $new_region;
$this
->setComponent($name, $component);
}
}
}
$this
->setThirdPartySetting('field_layout', 'id', $layout_id);
// Instantiate the plugin and consult it for the updated plugin
// configuration. Once layouts are no longer stored as third party settings,
// this will be handled by the code in
// \Drupal\Core\Config\Entity\ConfigEntityBase::set() that handles
// \Drupal\Core\Entity\EntityWithPluginCollectionInterface.
$layout_settings = $this
->doGetLayout($layout_id, $layout_settings)
->getConfiguration();
$this
->setThirdPartySetting('field_layout', 'settings', $layout_settings);
return $this;
}