You are here

protected function LayoutBuilderEntityViewDisplay::addTranslationField in Layout Builder Symmetric Translations 8

Adds a layout translation field to a given bundle.

Parameters

string $entity_type_id: The entity type ID.

string $bundle: The bundle.

string $field_name: The name for the translation field.

1 call to LayoutBuilderEntityViewDisplay::addTranslationField()
LayoutBuilderEntityViewDisplay::addSectionField in src/Entity/LayoutBuilderEntityViewDisplay.php
Adds a layout section field to a given bundle.

File

src/Entity/LayoutBuilderEntityViewDisplay.php, line 34

Class

LayoutBuilderEntityViewDisplay
Layout Entity Display overridden to add translation field.

Namespace

Drupal\layout_builder_st\Entity

Code

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