123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- <?php
- namespace Drupal\heartbeat\Entity;
- use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
- use Drupal\Core\Entity\EntityStorageInterface;
- use Drupal\heartbeat\HeartbeatTypeListBuilder;
- /**
- * Defines the Heartbeat type entity.
- *
- * @ConfigEntityType(
- * id = "heartbeat_type",
- * label = @Translation("Heartbeat type"),
- * handlers = {
- * "list_builder" = "Drupal\heartbeat\HeartbeatTypeListBuilder",
- * "form" = {
- * "add" = "Drupal\heartbeat\Form\HeartbeatTypeForm",
- * "edit" = "Drupal\heartbeat\Form\HeartbeatTypeForm",
- * "delete" = "Drupal\heartbeat\Form\HeartbeatTypeDeleteForm"
- * },
- * "route_provider" = {
- * "html" = "Drupal\heartbeat\HeartbeatTypeHtmlRouteProvider",
- * },
- * },
- * config_prefix = "heartbeat_type",
- * admin_permission = "administer site configuration",
- * bundle_of = "heartbeat",
- * entity_keys = {
- * "id" = "id",
- * "label" = "label",
- * "uuid" = "uuid"
- * },
- * links = {
- * "canonical" = "/admin/structure/heartbeat_type/{heartbeat_type}",
- * "add-form" = "/admin/structure/heartbeat_type/add",
- * "edit-form" = "/admin/structure/heartbeat_type/{heartbeat_type}/edit",
- * "delete-form" = "/admin/structure/heartbeat_type/{heartbeat_type}/delete",
- * "collection" = "/admin/structure/heartbeat_type"
- * }
- * )
- */
- class HeartbeatType extends ConfigEntityBundleBase implements HeartbeatTypeInterface {
- /**
- * The Heartbeat Stream ID.
- *
- * @var string
- */
- protected $id;
- protected $messageId;
- protected $hid;
- protected $description;
- protected $perms;
- protected $messageConcat;
- protected $arguments;
- protected $message;
- protected $variables;
- protected $attachments;
- protected $groupType;
- protected $mainentity;
- protected $entityManager;
- /**
- * The Heartbeat Stream label.
- *
- * @var string
- */
- protected $label;
- public static function getHeartbeatTypeEntity($messageId) {
- $entity_manager = \Drupal::entityTypeManager();
- }
- public function setMessageId($messageId) {
- $this->messageId = $messageId;
- }
- public function getMessageId() {
- return $this->messageId;
- }
- /**
- * Sets the description of the stream
- *
- * @param string $description
- * Describing streams of this type
- */
- public function setDescription($description) {
- $this->description = $description;
- }
- /**
- * Gets the description of the stream
- *
- * @return string
- * The Stream's description
- */
- public function getDescription() {
- return $this->description;
- }
- /**
- * Sets the translatable message
- * This message creates the structure of each message
- *
- * @param string $message
- * The template message serving as the foundation of each message structure of this stream type
- */
- public function setMessage($message) {
- $this->set('message', $message);
- }
- /**
- * Gets the translatable message of the stream
- *
- * @return string
- * The Stream's message
- */
- public function getMessage() {
- return $this->get('message');
- }
- // /**
- // * Sets the translatable concatenated message
- // *
- // * @param string $messageConcat
- // *
- // */
- // public function setMessageConcat($messageConcat) {
- // $this->messageConcat = $messageConcat;
- // }
- //
- // /**
- // * Gets the concatenated message of the stream
- // *
- // * @return string
- // * The Stream's concatenated message
- // */
- // public function getMessageConcat() {
- // return $this->messageConcat;
- // }
- /**
- * Sets the Permissions for this message stream
- *
- * @param int $perms
- *
- */
- public function setPerms($perms) {
- $this->perms = $perms;
- }
- /**
- * Gets the Permissions of this message stream
- *
- * @return int
- * The stream's permissions
- */
- public function getPerms() {
- return $this->perms;
- }
- /**
- * Sets the Group Type for this message stream
- *
- * @param string $groupType
- *
- */
- public function setGroupType($groupType) {
- $this->groupType = $groupType;
- }
- /**
- * Gets the Group Type of this message stream
- *
- * @return string
- * The stream's Group Type
- */
- public function getGroupType() {
- return $this->groupType;
- }
- /**
- * Sets the arguments for the concatenated message
- *
- * @param string $arguments
- *
- */
- public function setArguments($arguments) {
- $this->set('arguments', $arguments);
- // $this->arguments = $arguments;
- }
- /**
- * Gets the arguments for the concatenated message
- *
- * @return string
- * The stream's arguments for the concatenated message
- */
- public function getArguments() {
- return $this->get('arguments');
- // return $this->arguments;
- }
- /**
- * Sets the variables for this message stream
- *
- * @param string $variables
- *
- */
- public function setVariables($variables) {
- $this->variables = $variables;
- }
- /**
- * Gets the variables of this message stream
- *
- * @return string
- * The stream's variables
- */
- public function getVariables() {
- return $this->variables;
- }
- /**
- * @inheritDoc
- */
- public function __construct(array $values, $entity_type)
- {
- parent::__construct($values, $entity_type);
- $this->entityManager = \Drupal::entityManager();
- $this->entityTypeManager = \Drupal::entityTypeManager();
- }
- /**
- * @inheritDoc
- */
- protected function entityManager(){
- return parent::entityManager();
- }
- /**
- * @inheritDoc
- */
- protected function entityTypeManager() {
- return parent::entityTypeManager();
- }
- /**
- * {@inheritdoc}
- */
- public function isLocked() {
- $locked = \Drupal::state()->get('heartbeat.type.locked');
- return isset($locked[$this->id()]) ? $locked[$this->id()] : FALSE;
- }
- /**
- *
- */
- public function loadHeartbeatType() {
- $this->entityTypeManager->getDefinitions();
- }
- /**
- * {@inheritdoc}
- */
- public function postSave(EntityStorageInterface $storage, $update = TRUE) {
- parent::postSave($storage, $update);
- if ($update && $this->getOriginalId() != $this->id()) {
- $update_count = heartbeat_type_update_heartbeats($this->getOriginalId(), $this->id());
- if ($update_count) {
- drupal_set_message(\Drupal::translation()->formatPlural($update_count,
- 'Changed the heartbeat type of 1 activity from %old-type to %type.',
- 'Changed the heartbeat type of @count activities from %old-type to %type.',
- [
- '%old-type' => $this->getOriginalId(),
- '%type' => $this->id(),
- ]));
- }
- }
- if ($update) {
- // Clear the cached field definitions as some settings affect the field
- // definitions.
- $this->entityManager()->clearCachedFieldDefinitions();
- }
- }
- /**
- * {@inheritdoc}
- */
- public static function postDelete(EntityStorageInterface $storage, array $entities) {
- parent::postDelete($storage, $entities);
- // Clear the heartbeat type cache to reflect the removal.
- $storage->resetCache(array_keys($entities));
- }
- /**
- * Sets the main Entity Type of the Heartbeat Type
- *
- * @param string $mainentity
- * Describing entity type used in this Heartbeat Type
- */
- public function setMainEntity($mainentity) {
- $this->set('mainentity', $mainentity);
- }
- /**
- * @return mixed|null
- *
- */
- public function getMainEntity() {
- return $this->get('mainentity');
- }
- /**
- * Sets the bundle targeted for this Heartbeat type
- *
- * @param string $variables
- *
- */
- public function setBundle($bundle) {
- $this->set('bundle', $bundle);
- }
- /**
- * Gets the bundle of this Heartbeat type
- *
- * @return string
- * The stream's variables
- */
- public function getBundle() {
- return $this->get('bundle');
- }
- /**
- * @return mixed
- */
- public function setWeight($weight) {
- $this->set('weight', $weight);
- }
- /**
- * @param $weight
- * @return mixed
- */
- public function getWeight() {
- return $this->get('weight');
- }
- }
|