HeartbeatType.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <?php
  2. namespace Drupal\heartbeat8\Entity;
  3. use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
  4. use Drupal\Core\Entity\EntityStorageInterface;
  5. use Drupal\heartbeat8\HeartbeatTypeListBuilder;
  6. /**
  7. * Defines the Heartbeat type entity.
  8. *
  9. * @ConfigEntityType(
  10. * id = "heartbeat_type",
  11. * label = @Translation("Heartbeat type"),
  12. * handlers = {
  13. * "list_builder" = "Drupal\heartbeat8\HeartbeatTypeListBuilder",
  14. * "form" = {
  15. * "add" = "Drupal\heartbeat8\Form\HeartbeatTypeForm",
  16. * "edit" = "Drupal\heartbeat8\Form\HeartbeatTypeForm",
  17. * "delete" = "Drupal\heartbeat8\Form\HeartbeatTypeDeleteForm"
  18. * },
  19. * "route_provider" = {
  20. * "html" = "Drupal\heartbeat8\HeartbeatTypeHtmlRouteProvider",
  21. * },
  22. * },
  23. * config_prefix = "heartbeat_type",
  24. * admin_permission = "administer site configuration",
  25. * bundle_of = "heartbeat",
  26. * entity_keys = {
  27. * "id" = "id",
  28. * "label" = "label",
  29. * "uuid" = "uuid"
  30. * },
  31. * links = {
  32. * "canonical" = "/admin/structure/heartbeat_type/{heartbeat_type}",
  33. * "add-form" = "/admin/structure/heartbeat_type/add",
  34. * "edit-form" = "/admin/structure/heartbeat_type/{heartbeat_type}/edit",
  35. * "delete-form" = "/admin/structure/heartbeat_type/{heartbeat_type}/delete",
  36. * "collection" = "/admin/structure/heartbeat_type"
  37. * }
  38. * )
  39. */
  40. class HeartbeatType extends ConfigEntityBundleBase implements HeartbeatTypeInterface {
  41. /**
  42. * The Heartbeat Stream ID.
  43. *
  44. * @var string
  45. */
  46. protected $id;
  47. protected $messageId;
  48. protected $hid;
  49. protected $description;
  50. protected $perms;
  51. protected $messageConcat;
  52. protected $concatArgs;
  53. protected $message;
  54. protected $variables;
  55. protected $attachments;
  56. protected $groupType;
  57. protected $entityManager;
  58. /**
  59. * The Heartbeat Stream label.
  60. *
  61. * @var string
  62. */
  63. protected $label;
  64. public static function getHeartbeatTypeEntity($messageId) {
  65. $entity_manager = \Drupal::entityTypeManager();
  66. }
  67. public function setMessageId($messageId) {
  68. $this->messageId = $messageId;
  69. }
  70. public function getMessageId() {
  71. return $this->messageId;
  72. }
  73. /**
  74. * Sets the description of the stream
  75. *
  76. * @param string $description
  77. * Describing streams of this type
  78. */
  79. public function setDescription($description) {
  80. $this->description = $description;
  81. }
  82. /**
  83. * Gets the description of the stream
  84. *
  85. * @return string
  86. * The Stream's description
  87. */
  88. public function getDescription() {
  89. return $this->description;
  90. }
  91. /**
  92. * Sets the translatable message
  93. * This message creates the structure of each message
  94. *
  95. * @param string $message
  96. * The template message serving as the foundation of each message structure of this stream type
  97. */
  98. public function setMessage($message) {
  99. $this->message = $message;
  100. }
  101. /**
  102. * Gets the translatable message of the stream
  103. *
  104. * @return string
  105. * The Stream's message
  106. */
  107. public function getMessage() {
  108. return $this->message;
  109. }
  110. /**
  111. * Sets the translatable concatenated message
  112. *
  113. * @param string $messageConcat
  114. *
  115. */
  116. public function setMessageConcat($messageConcat) {
  117. $this->messageConcat = $messageConcat;
  118. }
  119. /**
  120. * Gets the concatenated message of the stream
  121. *
  122. * @return string
  123. * The Stream's concatenated message
  124. */
  125. public function getMessageConcat() {
  126. return $this->messageConcat;
  127. }
  128. /**
  129. * Sets the Permissions for this message stream
  130. *
  131. * @param int $perms
  132. *
  133. */
  134. public function setPerms($perms) {
  135. $this->perms = $perms;
  136. }
  137. /**
  138. * Gets the Permissions of this message stream
  139. *
  140. * @return int
  141. * The stream's permissions
  142. */
  143. public function getPerms() {
  144. return $this->perms;
  145. }
  146. /**
  147. * Sets the Group Type for this message stream
  148. *
  149. * @param string $groupType
  150. *
  151. */
  152. public function setGroupType($groupType) {
  153. $this->groupType = $groupType;
  154. }
  155. /**
  156. * Gets the Group Type of this message stream
  157. *
  158. * @return string
  159. * The stream's Group Type
  160. */
  161. public function getGroupType() {
  162. return $this->groupType;
  163. }
  164. /**
  165. * Sets the arguments for the concatenated message
  166. *
  167. * @param string $concatArgs
  168. *
  169. */
  170. public function setConcatArgs($concatArgs) {
  171. $this->concatArgs = $concatArgs;
  172. }
  173. /**
  174. * Gets the arguments for the concatenated message
  175. *
  176. * @return string
  177. * The stream's arguments for the concatenated message
  178. */
  179. public function getConcateArgs() {
  180. return $this->concatArgs;
  181. }
  182. /**
  183. * Sets the variables for this message stream
  184. *
  185. * @param string $variables
  186. *
  187. */
  188. public function setVariables($variables) {
  189. $this->variables = $variables;
  190. }
  191. /**
  192. * Gets the variables of this message stream
  193. *
  194. * @return string
  195. * The stream's variables
  196. */
  197. public function getVariables() {
  198. return $this->variables;
  199. }
  200. /**
  201. * Sets the attachments for this message stream
  202. *
  203. * @param string $attachments
  204. *
  205. */
  206. public function setAttachments($attachments) {
  207. $this->attachments = $attachments;
  208. }
  209. /**
  210. * Gets the attachments of this message stream
  211. *
  212. * @return string
  213. * The stream's attachments
  214. */
  215. public function getAttachments() {
  216. return $this->attachments;
  217. }
  218. /**
  219. * @inheritDoc
  220. */
  221. public function __construct(array $values, $entity_type)
  222. {
  223. parent::__construct($values, $entity_type);
  224. $this->entityManager = \Drupal::entityManager();
  225. $this->entityTypeManager = \Drupal::entityTypeManager();
  226. }
  227. /**
  228. * @inheritDoc
  229. */
  230. protected function entityManager()
  231. {
  232. return parent::entityManager(); // TODO: Change the autogenerated stub
  233. }
  234. /**
  235. * @inheritDoc
  236. */
  237. protected function entityTypeManager()
  238. {
  239. return parent::entityTypeManager(); // TODO: Change the autogenerated stub
  240. }
  241. /**
  242. * {@inheritdoc}
  243. */
  244. public function isLocked() {
  245. $locked = \Drupal::state()->get('heartbeat.type.locked');
  246. return isset($locked[$this->id()]) ? $locked[$this->id()] : FALSE;
  247. }
  248. /**
  249. *
  250. */
  251. public function loadHeartbeatType() {
  252. $this->entityTypeManager->getDefinitions();
  253. }
  254. /**
  255. * {@inheritdoc}
  256. */
  257. public function postSave(EntityStorageInterface $storage, $update = TRUE) {
  258. parent::postSave($storage, $update);
  259. if ($update && $this->getOriginalId() != $this->id()) {
  260. $update_count = heartbeat_type_update_heartbeats($this->getOriginalId(), $this->id());
  261. if ($update_count) {
  262. drupal_set_message(\Drupal::translation()->formatPlural($update_count,
  263. 'Changed the heartbeat type of 1 activity from %old-type to %type.',
  264. 'Changed the heartbeat type of @count activities from %old-type to %type.',
  265. [
  266. '%old-type' => $this->getOriginalId(),
  267. '%type' => $this->id(),
  268. ]));
  269. }
  270. }
  271. if ($update) {
  272. // Clear the cached field definitions as some settings affect the field
  273. // definitions.
  274. $this->entityManager()->clearCachedFieldDefinitions();
  275. }
  276. }
  277. /**
  278. * {@inheritdoc}
  279. */
  280. public static function postDelete(EntityStorageInterface $storage, array $entities) {
  281. parent::postDelete($storage, $entities);
  282. // Clear the heartbeat type cache to reflect the removal.
  283. $storage->resetCache(array_keys($entities));
  284. }
  285. }