You are here

public function LingotekConfigTranslationService::loadByDocumentId in Lingotek Translation 3.4.x

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

Loads the entity with the given document id.

Parameters

string $document_id: The document id.

Return value

ContentEntityInterface The entity with the given document id.

Overrides LingotekConfigTranslationServiceInterface::loadByDocumentId

File

src/LingotekConfigTranslationService.php, line 1580

Class

LingotekConfigTranslationService
Service for managing Lingotek configuration translations.

Namespace

Drupal\lingotek

Code

public function loadByDocumentId($document_id) {

  // We cannot use a mapping table as in content, because config can be staged.
  $entity = NULL;

  // Check config first.
  $config_mappers = array_filter($this->mappers, function ($mapper) {
    return $mapper instanceof ConfigNamesMapper && !$mapper instanceof ConfigEntityMapper && !$mapper instanceof ConfigFieldMapper;
  });
  foreach ($config_mappers as $mapper_id => $mapper) {
    if ($this
      ->getConfigDocumentId($mapper) === $document_id) {
      return $mapper;
    }
  }

  // If we failed, check config entities.
  foreach ($this->mappers as $mapper_id => $mapper) {
    if (!isset($config_mappers[$mapper_id])) {
      $id = NULL;
      if (substr($mapper_id, -7) == '_fields') {

        // Hack for fields, the entity is field config.
        $mapper_id = 'field_config';
      }
      $id = $this->entityTypeManager
        ->getStorage('lingotek_config_metadata')
        ->getQuery()
        ->condition('document_id', $document_id)
        ->execute();
      if (!empty($id)) {
        list($mapper_id, $entity_id) = explode('.', reset($id), 2);
        return $this->entityTypeManager
          ->getStorage($mapper_id)
          ->load($entity_id);
      }
    }
  }
  return NULL;
}