FilebrowserMetadataEntity.php in Filebrowser 8.2
File
src/Entity/FilebrowserMetadataEntity.php
View source
<?php
namespace Drupal\filebrowser\Entity;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\node\Entity\Node;
use Drupal\user\UserInterface;
class FilebrowserMetadataEntity extends ContentEntityBase implements FilebrowserMetadataEntityInterface {
use EntityChangedTrait;
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
parent::preCreate($storage_controller, $values);
$values += [
'user_id' => \Drupal::currentUser()
->id(),
];
}
public function getName() {
return $this
->get('name')->value;
}
public function setName($name) {
$this
->set('name', $name);
return $this;
}
public function getCreatedTime() {
return $this
->get('created')->value;
}
public function setCreatedTime($timestamp) {
$this
->set('created', $timestamp);
return $this;
}
public function getOwner() {
return $this
->get('user_id')->entity;
}
public function getOwnerId() {
return $this
->get('user_id')->target_id;
}
public function setOwnerId($uid) {
$this
->set('user_id', $uid);
return $this;
}
public function setOwner(UserInterface $account) {
$this
->set('user_id', $account
->id());
return $this;
}
public function isPublished() {
return (bool) $this
->getEntityKey('status');
}
public function setPublished($published) {
$this
->set('status', $published ? Node::PUBLISHED : Node::NOT_PUBLISHED);
return $this;
}
public function getContent() {
return $this
->get('content')
->getValue();
}
public function setContent($content) {
$this
->get('content')
->setValue($content);
}
public function getFid() {
return $this
->get('fid')
->getValue();
}
public function setFid($fid) {
$this
->get('fid')
->setValue($fid);
}
public function getModule() {
return $this
->get('module')
->getValue();
}
public function setModule($fid) {
$this
->get('fid')
->setValue($fid);
}
public function getTheme() {
return $this
->get('theme')
->getValue();
}
public function setTheme($fid) {
$this
->get('theme')
->setValue($fid);
}
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the Metadata entity entity.'))
->setReadOnly(TRUE);
$fields['fid'] = BaseFieldDefinition::create('integer')
->setRequired(true);
$fields['nid'] = BaseFieldDefinition::create('integer')
->setRequired(true);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Machine readable name'))
->setDescription(t('The machine name of the Filebrowser Metadata entity.'))
->setSettings([
'max_length' => 50,
'text_processing' => 0,
]);
$fields['title'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The Name of the Filebrowser Metadata entity.'))
->setSettings([
'max_length' => 50,
'text_processing' => 0,
]);
$fields['module'] = BaseFieldDefinition::create('string')
->setRequired(true);
$fields['theme'] = BaseFieldDefinition::create('string');
$fields['content'] = BaseFieldDefinition::create('string_long');
return $fields;
}
}