MaestroProcess.php in Maestro 3.x
File
src/Entity/MaestroProcess.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\maestro\MaestroProcessInterface;
use Drupal\user\UserInterface;
use Drupal\Core\Entity\EntityChangedTrait;
class MaestroProcess extends ContentEntityBase implements MaestroProcessInterface {
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 $this
->get('created')->value;
}
public function getChangedTime() {
return $this
->get('changed')->value;
}
public function getOwner() {
return $this
->get('initiator_uid')->entity;
}
public function getOwnerId() {
return $this
->get('initiator_uid')->target_id;
}
public function setOwnerId($uid) {
$this
->set('initiator_uid', $uid);
return $this;
}
public function setOwner(UserInterface $account) {
$this
->set('initiator_uid', $account
->id());
return $this;
}
public function getCompletedTime() {
return $this
->get('completed')->value;
}
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['process_id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ProcessID'))
->setDescription(t('The ID of the Maestro Process.'))
->setReadOnly(TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the Maestro Process entity.'))
->setReadOnly(TRUE);
$fields['process_name'] = BaseFieldDefinition::create('string')
->setLabel(t('Process Name'))
->setDescription(t('The Process Name. Carried from the Template.'))
->setSettings([
'default_value' => '',
'max_length' => 255,
'text_processing' => 0,
]);
$fields['template_id'] = BaseFieldDefinition::create('string')
->setLabel(t('Template Machine Name/ID'))
->setDescription(t('Machine name of the template.'))
->setSettings([
'default_value' => '',
'max_length' => 255,
'text_processing' => 0,
]);
$fields['complete'] = BaseFieldDefinition::create('integer')
->setLabel(t('Complete Flag'))
->setDescription(t('Completion flag'))
->setSettings([
'default_value' => '0',
]);
$fields['initiator_uid'] = BaseFieldDefinition::create('integer')
->setLabel(t('User ID of the initiator.'))
->setDescription(t('Initiator User ID'))
->setSettings([
'default_value' => '0',
]);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the process was created.'));
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the process entity was last edited.'));
$fields['completed'] = BaseFieldDefinition::create('integer')
->setLabel(t('Completed'))
->setDescription(t('The time that the process was completed.'))
->setSettings([
'default_value' => '0',
]);
return $fields;
}
}