ContentTranslationMetadataWrapper.php in Zircon Profile 8
File
core/modules/content_translation/src/ContentTranslationMetadataWrapper.php
View source
<?php
namespace Drupal\content_translation;
use Drupal\Core\Entity\EntityInterface;
use Drupal\user\UserInterface;
class ContentTranslationMetadataWrapper implements ContentTranslationMetadataWrapperInterface {
protected $translation;
protected $handler;
public function __construct(EntityInterface $translation, ContentTranslationHandlerInterface $handler) {
$this->translation = $translation;
$this->handler = $handler;
}
public function getSource() {
return $this->translation
->get('content_translation_source')->value;
}
public function setSource($source) {
$this->translation
->set('content_translation_source', $source);
return $this;
}
public function isOutdated() {
return (bool) $this->translation
->get('content_translation_outdated')->value;
}
public function setOutdated($outdated) {
$this->translation
->set('content_translation_outdated', $outdated);
return $this;
}
public function getAuthor() {
return $this->translation
->hasField('content_translation_uid') ? $this->translation
->get('content_translation_uid')->entity : $this->translation
->getOwner();
}
public function setAuthor(UserInterface $account) {
$field_name = $this->translation
->hasField('content_translation_uid') ? 'content_translation_uid' : 'uid';
$this
->setFieldOnlyIfTranslatable($field_name, $account
->id());
return $this;
}
public function isPublished() {
$field_name = $this->translation
->hasField('content_translation_status') ? 'content_translation_status' : 'status';
return (bool) $this->translation
->get($field_name)->value;
}
public function setPublished($published) {
$field_name = $this->translation
->hasField('content_translation_status') ? 'content_translation_status' : 'status';
$this
->setFieldOnlyIfTranslatable($field_name, $published);
return $this;
}
public function getCreatedTime() {
$field_name = $this->translation
->hasField('content_translation_created') ? 'content_translation_created' : 'created';
return $this->translation
->get($field_name)->value;
}
public function setCreatedTime($timestamp) {
$field_name = $this->translation
->hasField('content_translation_created') ? 'content_translation_created' : 'created';
$this
->setFieldOnlyIfTranslatable($field_name, $timestamp);
return $this;
}
public function getChangedTime() {
return $this->translation
->hasField('content_translation_changed') ? $this->translation
->get('content_translation_changed')->value : $this->translation
->getChangedTime();
}
public function setChangedTime($timestamp) {
$field_name = $this->translation
->hasField('content_translation_changed') ? 'content_translation_changed' : 'changed';
$this
->setFieldOnlyIfTranslatable($field_name, $timestamp);
return $this;
}
protected function setFieldOnlyIfTranslatable($field_name, $value) {
if ($this->translation
->getFieldDefinition($field_name)
->isTranslatable()) {
$this->translation
->set($field_name, $value);
}
}
}