layout_builder_st.install in Layout Builder Symmetric Translations 8
File
layout_builder_st.install
View source
<?php
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\layout_builder_st\Plugin\SectionStorage\OverridesSectionStorage;
function layout_builder_st_install() {
$field_manager = \Drupal::service('entity_field.manager');
$field_map = $field_manager
->getFieldMap();
foreach ($field_map as $entity_type_id => $field_infos) {
if (isset($field_infos[\Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage::FIELD_NAME]['bundles'])) {
$non_translatable_bundle_count = 0;
foreach ($field_infos[OverridesSectionStorage::FIELD_NAME]['bundles'] as $bundle) {
$bundles_not_added = [];
if (!($field_config = FieldConfig::loadByName($entity_type_id, $bundle, OverridesSectionStorage::FIELD_NAME))) {
continue;
}
_layout_builder_st_add_translation_field($entity_type_id, $bundle);
}
}
}
}
function _layout_builder_st_add_translation_field($entity_type_id, $bundle) {
$field_name = OverridesSectionStorage::TRANSLATED_CONFIGURATION_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();
}
}
function layout_builder_st_requirements($phase) {
$requirements = [];
if ($phase === 'install' && \Drupal::moduleHandler()
->moduleExists('layout_builder_at')) {
$requirements['layout_builder_at_incompatibility'] = [
'severity' => REQUIREMENT_ERROR,
'description' => t('Layout Builder Symmetric Translations can not be installed when Layout Builder Asymmetric Translations is also installed.'),
];
}
if ($phase === 'runtime' && \Drupal::moduleHandler()
->moduleExists('layout_builder_at')) {
$requirements['layout_builder_at_incompatibility'] = [
'severity' => REQUIREMENT_ERROR,
'description' => t('Layout Builder Symmetric Translations is not compatible with Layout Builder Asymmetric Translations. One of these should be uninstalled'),
];
}
return $requirements;
}