You are here

HeartbeatTypeService.php in Heartbeat 8

Namespace

Drupal\heartbeat

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.
 *
 * @package Drupal\heartbeat
 */
class HeartbeatTypeService {

  /**
   * Drupal\Core\Entity\EntityTypeManager definition.
   *
   * @var EntityTypeManager
   */
  protected $entityTypeManager;

  /**
    +   * Drupal\Core\Entity\EntityTypeBundleInfo definition.
    +   *
    +   * @var EntityTypeBundleInfo
    +   */
  protected $entityTypeBundleInfo;

  /**
   * Drupal\Core\Entity\Query\QueryFactory definition.
   *
   * @var \Drupal\Core\Entity\Query\QueryFactory
   */
  protected $entityQuery;

  /**
   * Constructor.
   * @param EntityTypeManager $entityTypeManager
   * @param EntityTypeBundleInfo $entityTypeBundleInfo
   * @param QueryFactory $entity_query
   */
  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());
  }

}

Classes

Namesort descending Description
HeartbeatTypeService Class HeartbeatTypeService.