TeamMemberRole.php in Apigee Edge 8
File
modules/apigee_edge_teams/src/Entity/TeamMemberRole.php
View source
<?php
namespace Drupal\apigee_edge_teams\Entity;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\user\UserInterface;
final class TeamMemberRole extends ContentEntityBase implements TeamMemberRoleInterface {
use EntityChangedTrait;
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = [];
$fields[$entity_type
->getKey('id')] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setReadOnly(TRUE);
$fields['uid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('User'))
->setDescription(t('The Drupal user of the developer.'))
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setRequired(TRUE)
->setDisplayConfigurable('view', FALSE)
->setDisplayConfigurable('form', FALSE);
$fields['team'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Team'))
->setDescription(t('A team that the developer belongs.'))
->setSetting('target_type', 'team')
->setSetting('handler', 'default')
->setRequired(TRUE)
->setDisplayConfigurable('view', FALSE)
->setDisplayConfigurable('form', FALSE);
$fields['roles'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Roles'))
->setDescription(t('The team roles of the developer within the team, except member, because that is an implied role.'))
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setSetting('target_type', 'team_role')
->setSetting('handler', 'default')
->setRequired(TRUE)
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE);
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t("The time that team member's roles were last edited."))
->setTranslatable(TRUE);
return $fields;
}
public function getDeveloper() : ?UserInterface {
return $this
->getOwner();
}
public function getTeam() : ?TeamInterface {
return $this
->get('team')->entity;
}
public function getTeamRoles() : array {
$roles = [];
foreach ($this
->get('roles') as $reference) {
if ($reference->entity === NULL) {
continue;
}
$roles[$reference->entity
->id()] = $reference->entity;
}
return $roles;
}
public function getOwner() {
return $this
->get('uid')->entity;
}
public function setOwner(UserInterface $account) {
return $this
->set('uid', $account
->id());
}
public function getOwnerId() {
return $this
->get('uid')->target_id;
}
public function setOwnerId($uid) {
return $this
->set('uid', $uid);
}
public function getCacheTags() {
if ($this
->getTeam()) {
$this->cacheTags = array_merge($this->cacheTags, $this
->getTeam()
->getCacheTags());
}
if ($this
->getDeveloper()) {
$this->cacheTags = array_merge($this->cacheTags, $this
->getDeveloper()
->getCacheTags());
}
return parent::getCacheTags();
}
}