You are here

public function LingotekProfileUsage::isUsedByConfig in Lingotek Translation 3.1.x

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

Check if a profile is configured to be used by config entities.

Parameters

\Drupal\lingotek\LingotekProfileInterface $profile: The profile being checked.

Return value

int Bitwise flag. Can include LingotekProfileUsageInterface::USED_BY_CONFIG or LingotekProfileUsageInterface::UNUSED.

Overrides LingotekProfileUsageInterface::isUsedByConfig

File

src/LingotekProfileUsage.php, line 75

Class

LingotekProfileUsage
Service for checking Lingotek profiles usage.

Namespace

Drupal\lingotek

Code

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;
    }
  }
  if ($used !== LingotekProfileUsageInterface::USED_BY_CONFIG) {
    $entity_query = $this->entityTypeManager
      ->getStorage('lingotek_config_metadata')
      ->getQuery();
    $entity_query
      ->condition('profile', $profile
      ->id());
    $result = $entity_query
      ->count()
      ->execute();
    $used = $result > 0 ? LingotekProfileUsageInterface::USED_BY_CONFIG : LingotekProfileUsageInterface::UNUSED;
  }
  return $used;
}