Workflow.php in Forms Steps 8
File
src/Entity/Workflow.php
View source
<?php
namespace Drupal\forms_steps\Entity;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\forms_steps\WorkflowInterface;
use Drupal\user\UserInterface;
class Workflow extends ContentEntityBase implements WorkflowInterface {
use EntityChangedTrait;
const ENTITY_TYPE = 'forms_steps_workflow';
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
parent::preCreate($storage_controller, $values);
$values += [
'user_id' => \Drupal::currentUser()
->id(),
];
}
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 static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the Workflow entity.'))
->setReadOnly(TRUE);
$fields['instance_id'] = BaseFieldDefinition::create('string')
->setLabel(t('Instance ID'))
->setDescription(t('The Instance ID of the Workflow entity.'))
->setReadOnly(TRUE);
$fields['entity_type'] = BaseFieldDefinition::create('string')
->setLabel(t('Entity Type'))
->setDescription(t('The Entity Type of the Workflow entity.'))
->setReadOnly(FALSE);
$fields['bundle'] = BaseFieldDefinition::create('string')
->setLabel(t('Bundle'))
->setDescription(t('The Bundle of the Workflow entity.'))
->setReadOnly(FALSE);
$fields['entity_id'] = BaseFieldDefinition::create('integer')
->setLabel(t('Entity ID'))
->setDescription(t('The ID of the entity id.'))
->setReadOnly(FALSE);
$fields['form_mode'] = BaseFieldDefinition::create('string')
->setLabel(t('Form Mode'))
->setDescription(t('The Form Mode of the Workflow entity.'))
->setReadOnly(FALSE);
$fields['forms_steps'] = BaseFieldDefinition::create('string')
->setLabel(t('Forms Steps'))
->setDescription(t('The Workflow machine name of the Workflow entity.'))
->setReadOnly(FALSE);
$fields['step'] = BaseFieldDefinition::create('string')
->setLabel(t('Step'))
->setDescription(t('The Step of the Workflow entity.'))
->setReadOnly(FALSE);
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('User Name'))
->setDescription(t('The Name of the associated user.'))
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'entity_reference',
'weight' => -3,
]);
$fields['langcode'] = BaseFieldDefinition::create('language')
->setLabel(t('Language code'))
->setDescription(t('The language code of inventory entity.'));
$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.'));
return $fields;
}
}