LingotekConfigMetadata.php in Lingotek Translation 3.8.x
File
src/Entity/LingotekConfigMetadata.php
View source
<?php
namespace Drupal\lingotek\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\field\Entity\FieldConfig;
use Drupal\lingotek\LingotekConfigMetadataInterface;
class LingotekConfigMetadata extends ConfigEntityBase implements LingotekConfigMetadataInterface {
protected $config_name;
protected $document_id;
protected $source_status = [];
protected $target_status = [];
protected $profile = NULL;
protected $hash = NULL;
protected $job_id = '';
protected $uploaded_timestamp = NULL;
protected $updated_timestamp = NULL;
public function getDocumentId() {
return $this->document_id;
}
public function setDocumentId($document_id) {
$this->document_id = $document_id;
return $this;
}
public function getSourceStatus() {
return $this->source_status;
}
public function setSourceStatus(array $source_status) {
$this->source_status = $source_status;
return $this;
}
public function getTargetStatus() {
return $this->target_status;
}
public function setTargetStatus(array $target_status) {
$this->target_status = $target_status;
return $this;
}
public function getProfile() {
return $this->profile;
}
public function setProfile($profile) {
$this->profile = $profile;
return $this;
}
public function getHash() {
return $this->hash;
}
public function setHash($hash) {
$this->hash = $hash;
return $this;
}
public function getJobId() {
return $this->job_id;
}
public function setJobId($job_id) {
$this->job_id = $job_id;
return $this;
}
public function setLastUpdated($timestamp) {
$this->updated_timestamp = $timestamp;
return $this;
}
public function getLastUpdated() {
return $this->updated_timestamp;
}
public function setLastUploaded($timestamp) {
$this->uploaded_timestamp = $timestamp;
return $this;
}
public function getLastUploaded() {
return $this->uploaded_timestamp;
}
public static function loadByConfigName($config_name) {
if ($config_name == NULL) {
return NULL;
}
$storage = \Drupal::entityTypeManager()
->getStorage('lingotek_config_metadata');
$config = $storage
->load($config_name);
if ($config == NULL) {
$config = $storage
->create([
'config_name' => $config_name,
]);
}
return $config;
}
public function id() {
return $this->config_name;
}
public function calculateDependencies() {
parent::calculateDependencies();
$dependency_name = $this
->getDependencyName();
$this
->addDependency('config', $dependency_name);
return $this;
}
public function getDependencyName() {
list($entity_type, $entity_id) = explode('.', $this->config_name, 2);
if ($entity_type === 'field_config') {
$field_config = FieldConfig::load($entity_id);
$value = $field_config
->getConfigDependencyName();
}
elseif ($this
->entityTypeManager()
->hasDefinition($entity_type)) {
$storage = $this
->entityTypeManager()
->getStorage($entity_type);
$entity = $storage
->load($entity_id);
$value = $entity ? $entity
->getConfigDependencyName() : $this->config_name;
}
else {
$value = $this->config_name;
}
return $value;
}
public function getConfigMapper() {
$mapper = NULL;
$mappers = \Drupal::service('plugin.manager.config_translation.mapper')
->getMappers();
$name = $this
->getDependencyName();
$config_mapper_id = $this
->getMapperIdForName($name);
if (isset($mappers[$config_mapper_id])) {
$mapper = $mappers[$config_mapper_id];
}
else {
list($entity_type, $entity_id) = explode('.', $this->config_name, 2);
if (isset($mappers[$entity_type])) {
$storage = $this
->entityTypeManager()
->getStorage($entity_type);
$entity = $storage
->load($entity_id);
$mapper = clone $mappers[$entity_type];
$mapper
->setEntity($entity);
}
}
return $mapper;
}
protected function getMapperIdForName($name) {
$mapper_id = NULL;
$config_mappers = \Drupal::service('plugin.manager.config_translation.mapper')
->getMappers();
foreach ($config_mappers as $config_mapper_id => $config_mapper) {
$names = $config_mapper
->getConfigNames();
if (in_array($name, $names)) {
$mapper_id = $config_mapper_id;
break;
}
}
return $mapper_id;
}
}