LayoutBuilderEntityViewDisplay.php in Layout Builder Symmetric Translations 8
File
src/Entity/LayoutBuilderEntityViewDisplay.php
View source
<?php
namespace Drupal\layout_builder_st\Entity;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay as CoreLayoutBuilderEntityViewDisplay;
use Drupal\layout_builder\Entity\LayoutEntityDisplayInterface;
use Drupal\layout_builder_st\Plugin\SectionStorage\OverridesSectionStorage;
final class LayoutBuilderEntityViewDisplay extends CoreLayoutBuilderEntityViewDisplay implements LayoutEntityDisplayInterface {
protected function addSectionField($entity_type_id, $bundle, $field_name) {
parent::addSectionField($entity_type_id, $bundle, $field_name);
$this
->addTranslationField($entity_type_id, $bundle, OverridesSectionStorage::TRANSLATED_CONFIGURATION_FIELD_NAME);
}
protected function addTranslationField($entity_type_id, $bundle, $field_name) {
$field = FieldConfig::loadByName($entity_type_id, $bundle, $field_name);
if (!$field) {
$field_storage = FieldStorageConfig::loadByName($entity_type_id, $field_name);
if (!$field_storage) {
$field_storage = FieldStorageConfig::create([
'entity_type' => $entity_type_id,
'field_name' => $field_name,
'type' => 'layout_translation',
'locked' => TRUE,
]);
$field_storage
->setTranslatable(TRUE);
$field_storage
->save();
}
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => $bundle,
'label' => t('Layout Labels'),
]);
$field
->save();
}
}
}