View source
<?php
namespace Drupal\heartbeat\Entity;
use Drupal\heartbeat\Entity\HeartbeatType;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Entity\RevisionableContentEntityBase;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\user\UserInterface;
class HeartbeatStream extends RevisionableContentEntityBase implements HeartbeatStreamInterface {
use EntityChangedTrait;
protected $class;
protected $realClass;
protected $name;
protected $module;
protected $title;
protected $path;
protected $settings;
protected $variables;
protected $types;
protected $weight;
public function getTypes() {
return $this
->get('types');
}
public function setTypes($types) {
$this
->set('types', $types);
return $this;
}
public function getClass() {
return $this
->get('class');
}
public function setClass($class) {
$this
->set('class', $class);
}
public function getRealClass() {
return $this
->get('realClass');
}
public function setRealClass($realClass) {
$this
->set('realClass', $realClass);
}
public function getModule() {
return $this
->get('module');
}
public function setModule($module) {
$this
->set('module', $module);
}
public function getTitle() {
return $this
->get('title');
}
public function setTitle($title) {
$this
->set('title', $title);
}
public function getPath() {
return $this
->get('path');
}
public function setPath($path) {
$this
->set('path', $path);
}
public function getSettings() {
return $this
->get('settings');
}
public function setSettings($settings) {
$this
->set('settings ', $settings);
}
public function getVariables() {
return $this
->get('variables');
}
public function setVariables($variables) {
$this
->set('variables', $variables);
}
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
parent::preCreate($storage_controller, $values);
$values += array(
'user_id' => \Drupal::currentUser()
->id(),
);
}
public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage);
foreach (array_keys($this
->getTranslationLanguages()) as $langcode) {
$translation = $this
->getTranslation($langcode);
if (!$translation
->getOwner()) {
$translation
->setOwnerId(0);
}
}
if (!$this
->getRevisionUser()) {
$this
->setRevisionUserId($this
->getOwnerId());
}
}
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 ? TRUE : FALSE);
return $this;
}
public function getRevisionCreationTime() {
return $this
->get('revision_timestamp')->value;
}
public function setRevisionCreationTime($timestamp) {
$this
->set('revision_timestamp', $timestamp);
return $this;
}
public function getRevisionUser() {
return $this
->get('revision_uid')->entity;
}
public function setRevisionUserId($uid) {
$this
->set('revision_uid', $uid);
return $this;
}
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Authored by'))
->setDescription(t('The user ID of author of the Heartbeat stream entity.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setTranslatable(TRUE)
->setDisplayOptions('view', array(
'label' => 'hidden',
'type' => 'author',
'weight' => 0,
))
->setDisplayOptions('form', array(
'type' => 'entity_reference_autocomplete',
'weight' => 5,
'settings' => array(
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
),
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['path'] = BaseFieldDefinition::create('string')
->setLabel(t('Path'))
->setSettings(array(
'max_length' => 255,
));
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The name of the Heartbeat stream entity.'))
->setRevisionable(TRUE)
->setSettings(array(
'max_length' => 50,
'text_processing' => 0,
))
->setDefaultValue('')
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'string',
'weight' => -4,
))
->setDisplayOptions('form', array(
'type' => 'string_textfield',
'weight' => -4,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Publishing status'))
->setDescription(t('A boolean indicating whether the Heartbeat stream is published.'))
->setRevisionable(TRUE)
->setDefaultValue(TRUE);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the entity was created.'));
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the entity was last edited.'));
$fields['revision_timestamp'] = BaseFieldDefinition::create('created')
->setLabel(t('Revision timestamp'))
->setDescription(t('The time that the current revision was created.'))
->setQueryable(FALSE)
->setRevisionable(TRUE);
$fields['revision_uid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Revision user ID'))
->setDescription(t('The user ID of the author of the current revision.'))
->setSetting('target_type', 'user')
->setQueryable(FALSE)
->setRevisionable(TRUE);
$fields['types'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Heartbeat Types'))
->setDescription(t('The Heartbeat Types included in this stream'))
->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
->setRequired(TRUE)
->setRevisionable(TRUE)
->setSetting('target_type', 'heartbeat_type');
$fields['weight'] = BaseFieldDefinition::create('integer')
->setLabel(t('Weight'))
->setDescription(t('The weight of the stream'))
->setDefaultValue(0);
return $fields;
}
public function setWeight($weight) {
$this
->set('weight', $weight);
}
public function getWeight() {
return $this
->get('weight');
}
}