public function LockFieldsManager::getTranslatableFieldsByContentEntity in TMGMT Translator Smartling 8.4
Returns list of translatable fields for a given entity.
Parameters
ContentEntityInterface $entity:
Return value
array
File
- src/
Smartling/ LockFields/ LockFieldsManager.php, line 47
Class
- LockFieldsManager
- Class LockFieldsManager
Namespace
Drupal\tmgmt_smartling\Smartling\LockFieldsCode
public function getTranslatableFieldsByContentEntity(ContentEntityInterface $entity) {
$field_definitions = $entity
->getFieldDefinitions();
$exclude_field_types = [
'language',
];
$exclude_field_names = [
'moderation_state',
'default_langcode',
'revision_translation_affected',
'content_translation_outdated',
'content_translation_uid',
'content_translation_created',
];
return array_map(function (FieldDefinitionInterface $field_definition) {
return $field_definition
->getLabel();
}, array_filter($field_definitions, function (FieldDefinitionInterface $field_definition) use ($exclude_field_types, $exclude_field_names) {
// Field is not translatable.
if (!$field_definition
->isTranslatable()) {
return FALSE;
}
// Field type matches field types to exclude.
if (in_array($field_definition
->getType(), $exclude_field_types)) {
return FALSE;
}
// Field name matches field names to exclude.
if (in_array($field_definition
->getName(), $exclude_field_names)) {
return FALSE;
}
// User marked the field to be excluded.
if ($field_definition instanceof ThirdPartySettingsInterface) {
$is_excluded = $field_definition
->getThirdPartySetting('tmgmt_content', 'excluded', FALSE);
if ($is_excluded) {
return FALSE;
}
}
return TRUE;
}));
}