lingotek_test.module in Lingotek Translation 8
File
tests/modules/lingotek_test/lingotek_test.module
View source
<?php
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Serialization\Yaml;
function lingotek_test_lingotek_content_entity_translation_presave(ContentEntityInterface &$translation, $langcode, $data) {
if ($translation
->getEntityTypeId() === 'node' && $translation
->bundle() === 'press_release') {
if ($translation
->isNewTranslation()) {
$translation
->setPublished(FALSE);
}
}
}
function lingotek_test_lingotek_content_entity_document_upload(array &$source_data, ContentEntityInterface &$entity, &$url) {
if ($entity
->getEntityTypeId() === 'node' && $entity
->bundle() === 'animal') {
$url = \Drupal::request()
->getBasePath() . '/animal/2016/llamas-are-cool';
$source_data['animal_date'] = '2016-05-01';
}
}
function lingotek_test_lingotek_config_entity_translation_presave(ConfigEntityInterface &$translation, $langcode, &$data) {
switch ($translation
->getEntityTypeId()) {
case 'block':
$yaml = Yaml::encode($data);
$yaml = preg_replace_callback('/\\[\\*\\*\\*([^]]+)\\*\\*\\*\\]/', function ($matches) {
return '[' . base64_decode($matches[1]) . ']';
}, $yaml);
$data = Yaml::decode($yaml);
break;
}
}
function lingotek_test_lingotek_config_entity_document_upload(array &$source_data, ConfigEntityInterface &$entity, &$url) {
switch ($entity
->getEntityTypeId()) {
case 'block':
$yaml = Yaml::encode($source_data);
$yaml = preg_replace_callback('/\\[([a-z][^]]+)\\]/', function ($matches) {
return '[***' . base64_encode($matches[1]) . '***]';
}, $yaml);
$source_data = Yaml::decode($yaml);
break;
}
}