You are here

class LingotekProfileUsage in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 src/LingotekProfileUsage.php \Drupal\lingotek\LingotekProfileUsage
  2. 4.0.x src/LingotekProfileUsage.php \Drupal\lingotek\LingotekProfileUsage
  3. 3.0.x src/LingotekProfileUsage.php \Drupal\lingotek\LingotekProfileUsage
  4. 3.1.x src/LingotekProfileUsage.php \Drupal\lingotek\LingotekProfileUsage
  5. 3.2.x src/LingotekProfileUsage.php \Drupal\lingotek\LingotekProfileUsage
  6. 3.3.x src/LingotekProfileUsage.php \Drupal\lingotek\LingotekProfileUsage
  7. 3.4.x src/LingotekProfileUsage.php \Drupal\lingotek\LingotekProfileUsage
  8. 3.5.x src/LingotekProfileUsage.php \Drupal\lingotek\LingotekProfileUsage
  9. 3.6.x src/LingotekProfileUsage.php \Drupal\lingotek\LingotekProfileUsage
  10. 3.7.x src/LingotekProfileUsage.php \Drupal\lingotek\LingotekProfileUsage
  11. 3.8.x src/LingotekProfileUsage.php \Drupal\lingotek\LingotekProfileUsage

Service for checking Lingotek profiles usage.

Hierarchy

Expanded class hierarchy of LingotekProfileUsage

1 string reference to 'LingotekProfileUsage'
lingotek.services.yml in ./lingotek.services.yml
lingotek.services.yml
1 service uses LingotekProfileUsage
lingotek.profile_usage in ./lingotek.services.yml
Drupal\lingotek\LingotekProfileUsage

File

src/LingotekProfileUsage.php, line 11

Namespace

Drupal\lingotek
View source
class LingotekProfileUsage implements LingotekProfileUsageInterface {

  /**
   * The Lingotek configuration service.
   *
   * @var \Drupal\lingotek\LingotekConfigurationServiceInterface
   */
  protected $lingotekConfiguration;

  /**
   * The entity query factory service.
   *
   * @var \Drupal\Core\Entity\Query\QueryFactory
   */
  protected $entityQuery;

  /**
   * The configuration mapper manager.
   *
   * @var \Drupal\config_translation\ConfigMapperManagerInterface
   */
  protected $configMapperManager;

  /**
   * Constructs a new LingotekProfileUsage object.
   *
   * @param \Drupal\lingotek\LingotekConfigurationServiceInterface $lingotek_configuration
   *   The Lingotek configuration service.
   * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query
   *   The entity query factory.
   * @param \Drupal\config_translation\ConfigMapperManagerInterface $config_mapper_manager
   *   The configuration mapper manager.
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LingotekProfileUsage::$configMapperManager protected property The configuration mapper manager.
LingotekProfileUsage::$entityQuery protected property The entity query factory service.
LingotekProfileUsage::$lingotekConfiguration protected property The Lingotek configuration service.
LingotekProfileUsage::isUsedByConfig public function Check if a profile is configured to be used by config entities. Overrides LingotekProfileUsageInterface::isUsedByConfig
LingotekProfileUsage::isUsedByContent public function Check if a profile is used by content entities. Overrides LingotekProfileUsageInterface::isUsedByContent
LingotekProfileUsage::isUsedByContentSettings public function Check if a profile is configured to be used by content entities. Overrides LingotekProfileUsageInterface::isUsedByContentSettings
LingotekProfileUsage::__construct public function Constructs a new LingotekProfileUsage object.
LingotekProfileUsageInterface::UNUSED constant Bit flag constant for unused profiles.
LingotekProfileUsageInterface::USED_BY_CONFIG constant Bit flag constant for profiles configured to be used by config entities.
LingotekProfileUsageInterface::USED_BY_CONTENT constant Bit flag constant for profiles assigned to content.
LingotekProfileUsageInterface::USED_BY_SETTINGS constant Bit flag constant for profiles configured to be used by content entities.