BrightcoveCmsEntity.php in Brightcove Video Connect 3.x
File
src/Entity/BrightcoveCmsEntity.php
View source
<?php
namespace Drupal\brightcove\Entity;
use Drupal\brightcove\BrightcoveCMSEntityInterface;
use Drupal\brightcove\EntityChangedFieldsTrait;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\user\UserInterface;
abstract class BrightcoveCmsEntity extends ContentEntityBase implements BrightcoveCMSEntityInterface {
use EntityChangedTrait;
use EntityChangedFieldsTrait;
public function getName() {
return $this
->get('name')->value;
}
public function setName($name) {
$this
->set('name', $name);
return $this;
}
public function getApiClient() {
return $this
->get('api_client')->target_id;
}
public function setApiClient($api_client) {
$this
->set('api_client', $api_client);
return $this;
}
public function getDescription() {
return $this
->get('description')->value;
}
public function setDescription($description) {
$this
->set('description', $description);
return $this;
}
public function getOwner() {
return $this
->get('uid')->entity;
}
public function setOwner(UserInterface $account) {
$this
->set('uid', $account
->id());
return $this;
}
public function getOwnerId() {
return $this
->get('uid')->target_id;
}
public function setOwnerId($uid) {
$this
->set('uid', $uid);
return $this;
}
public function getCreatedTime() {
return $this
->get('created')->value;
}
public function setCreatedTime($timestamp) {
$this
->set('created', $timestamp);
return $this;
}
public function preSave(EntityStorageInterface $storage) {
$this
->checkUpdatedFields($storage);
return parent::preSave($storage);
}
public static function getCurrentUserId() {
return [
\Drupal::currentUser()
->id(),
];
}
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
parent::preCreate($storage_controller, $values);
$values += [
'uid' => \Drupal::currentUser()
->id(),
];
}
public static function loadMultipleByApiClient($api_client, $status = TRUE) {
$repository = \Drupal::getContainer()
->get('entity_type.repository');
$entity_ids = \Drupal::entityQuery($repository
->getEntityTypeFromClass(get_called_class()))
->condition('api_client', $api_client)
->condition('status', $status ? 1 : 0)
->execute();
return self::loadMultiple($entity_ids);
}
}