HeartbeatTypeService.php in Heartbeat 8
File
src/HeartbeatTypeService.php
View source
<?php
namespace Drupal\heartbeat;
use Drupal\Core\Entity\ContentEntityType;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Entity\EntityTypeBundleInfo;
use Drupal\Core\Entity\Query\QueryFactory;
class HeartbeatTypeService {
protected $entityTypeManager;
protected $entityTypeBundleInfo;
protected $entityQuery;
public function __construct(EntityTypeManager $entityTypeManager, EntityTypeBundleInfo $entityTypeBundleInfo, QueryFactory $entity_query) {
$this->entityTypeManager = $entityTypeManager;
$this->entityTypeBundleInfo = $entityTypeBundleInfo;
$this->entityQuery = $entity_query;
}
public function getTypes() {
return $this->entityQuery
->get('heartbeat_type')
->sort('weight', 'ASC')
->execute();
}
public function load($id) {
return $this->entityTypeManager
->getStorage('heartbeat_type')
->load($id);
}
public function getEntityBundles(ContentEntityType $entity) {
return $this->entityTypeBundleInfo
->getBundleInfo($entity
->id());
}
}