LingotekProfileUsage.php in Lingotek Translation 8
File
src/LingotekProfileUsage.php
View source
<?php
namespace Drupal\lingotek;
use Drupal\config_translation\ConfigMapperManagerInterface;
use Drupal\Core\Entity\Query\QueryFactory;
class LingotekProfileUsage implements LingotekProfileUsageInterface {
protected $lingotekConfiguration;
protected $entityQuery;
protected $configMapperManager;
public function __construct(LingotekConfigurationServiceInterface $lingotek_configuration, QueryFactory $entity_query, ConfigMapperManagerInterface $config_mapper_manager) {
$this->lingotekConfiguration = $lingotek_configuration;
$this->entityQuery = $entity_query;
$this->configMapperManager = $config_mapper_manager;
}
public function isUsedByContent(LingotekProfileInterface $profile) {
$entity_types = $this->lingotekConfiguration
->getEnabledEntityTypes();
$used = LingotekProfileUsageInterface::UNUSED;
foreach ($entity_types as $entity_type => $entity_type_definition) {
$entity_query = $this->entityQuery
->get($entity_type);
$entity_query
->condition('lingotek_profile', $profile
->id());
$result = $entity_query
->count()
->execute();
$used |= $result > 0 ? LingotekProfileUsageInterface::USED_BY_CONTENT : LingotekProfileUsageInterface::UNUSED;
}
return $used;
}
public function isUsedByConfig(LingotekProfileInterface $profile) {
$mappers = $this->configMapperManager
->getMappers();
$used = LingotekProfileUsageInterface::UNUSED;
foreach ($mappers as $plugin_id => $mapper) {
$config_profile = $this->lingotekConfiguration
->getConfigProfile($plugin_id, FALSE);
if ($config_profile !== NULL && $config_profile
->id() === $profile
->id()) {
$used |= LingotekProfileUsageInterface::USED_BY_CONFIG;
}
}
return $used;
}
public function isUsedByContentSettings(LingotekProfileInterface $profile) {
$entity_types = $this->lingotekConfiguration
->getEnabledEntityTypes();
$used = LingotekProfileUsageInterface::UNUSED;
foreach ($entity_types as $entity_type_id => $entity_type_definition) {
$bundles = \Drupal::entityManager()
->getBundleInfo($entity_type_id);
foreach ($bundles as $bundle_id => $bundle_definition) {
$config_profile = $this->lingotekConfiguration
->getDefaultProfileId($entity_type_id, $bundle_id);
if ($config_profile === $profile
->id()) {
$used |= LingotekProfileUsageInterface::USED_BY_SETTINGS;
}
}
}
return $used;
}
}