MaestroEntityIdentifiers.php in Maestro 3.x
File
src/Entity/MaestroEntityIdentifiers.php
View source
<?php
namespace Drupal\maestro\Entity;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\user\UserInterface;
use Drupal\Core\Entity\EntityChangedTrait;
class MaestroEntityIdentifiers extends ContentEntityBase {
use EntityChangedTrait;
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
parent::preCreate($storage_controller, $values);
$values += [
'user_id' => \Drupal::currentUser()
->id(),
];
}
public function getCreatedTime() {
return NULL;
}
public function getChangedTime() {
return NULL;
}
public function getOwner() {
return NULL;
}
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 getCompletedTime() {
return NULL;
}
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = [];
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('id'))
->setDescription(t('The unique ID of the Maestro Entity Identifiers entry.'))
->setReadOnly(TRUE);
$fields['process_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Process ID'))
->setDescription(t('The process ID this entity identifier belongs to.'))
->setSetting('target_type', 'maestro_process')
->setSetting('handler', 'default');
$fields['unique_id'] = BaseFieldDefinition::create('string')
->setLabel(t('Unique ID'))
->setDescription(t('The unique identifier for the task to bind to the identifier.'))
->setSettings([
'default_value' => '',
'max_length' => 255,
'text_processing' => 0,
]);
$fields['entity_type'] = BaseFieldDefinition::create('string')
->setLabel(t('Entity Type'))
->setDescription(t('The type of entity.'))
->setSettings([
'default_value' => '',
'max_length' => 255,
'text_processing' => 0,
]);
$fields['bundle'] = BaseFieldDefinition::create('string')
->setLabel(t('Bundle'))
->setDescription(t('The bundle associated to the entity_type.'))
->setSettings([
'default_value' => '',
'max_length' => 255,
'text_processing' => 0,
]);
$fields['entity_id'] = BaseFieldDefinition::create('string')
->setLabel(t('Entity ID'))
->setDescription(t('The ID of the entity.'))
->setSettings([
'default_value' => '',
'max_length' => 255,
'text_processing' => 0,
]);
return $fields;
}
}