class PrintableEntityManager in Printer and PDF versions for Drupal 8+ 8
Same name and namespace in other branches
- 2.x src/PrintableEntityManager.php \Drupal\printable\PrintableEntityManager
Helper class for the printable module.
Hierarchy
- class \Drupal\printable\PrintableEntityManager implements PrintableEntityManagerInterface
Expanded class hierarchy of PrintableEntityManager
1 file declares its use of PrintableEntityManager
- PrintableEntityManagerTest.php in tests/
src/ Unit/ PrintableEntityManagerTest.php
1 string reference to 'PrintableEntityManager'
1 service uses PrintableEntityManager
File
- src/
PrintableEntityManager.php, line 13
Namespace
Drupal\printableView source
class PrintableEntityManager implements PrintableEntityManagerInterface {
/**
* The entity manager service.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactory
*/
protected $configFactory;
/**
* The entity definitions of entities that have printable versions available.
*
* @var array
*/
protected $compatibleEntities = [];
/**
* Constructs a new PrintableEntityManager object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory service.
*/
public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory) {
$this->entityManager = $entity_manager;
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public function getEntityName(EntityInterface $entity) {
return $entity
->getEntityTypeId();
}
/**
* {@inheritdoc}
*/
public function getPrintableEntities() {
$compatible_entities = $this
->getCompatibleEntities();
$entities = [];
foreach ($this->configFactory
->get('printable.settings')
->get('printable_entities') as $entity_type) {
if (isset($compatible_entities[$entity_type])) {
$entities[$entity_type] = $compatible_entities[$entity_type];
}
}
return $entities;
}
/**
* {@inheritdoc}
*/
public function isPrintableEntity(EntityInterface $entity) {
return array_key_exists($entity
->getEntityTypeId(), $this
->getPrintableEntities());
}
/**
* {@inheritdoc}
*/
public function getCompatibleEntities() {
// If the entities are yet to be populated, get the entity definitions from
// the entity manager.
if (empty($this->compatibleEntities)) {
foreach ($this->entityManager
->getDefinitions() as $entity_type => $entity_definition) {
// If this entity has a render controller, it has a printable version.
if ($entity_definition
->hasHandlerClass('view_builder')) {
$this->compatibleEntities[$entity_type] = $entity_definition;
}
}
}
return $this->compatibleEntities;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PrintableEntityManager:: |
protected | property | The entity definitions of entities that have printable versions available. | |
PrintableEntityManager:: |
protected | property | The config factory service. | |
PrintableEntityManager:: |
protected | property | The entity manager service. | |
PrintableEntityManager:: |
public | function |
Get the entities that Printable can generate hardcopies for. Overrides PrintableEntityManagerInterface:: |
|
PrintableEntityManager:: |
public | function |
Gets the ID of the type of the entity. Overrides PrintableEntityManagerInterface:: |
|
PrintableEntityManager:: |
public | function |
Get the entities that printable is available for. Overrides PrintableEntityManagerInterface:: |
|
PrintableEntityManager:: |
public | function |
Check if an entity has a printable version available for it. Overrides PrintableEntityManagerInterface:: |
|
PrintableEntityManager:: |
public | function | Constructs a new PrintableEntityManager object. |