You are here

public static function MappingLoader::getMapping in GatherContent 8.4

Same name and namespace in other branches
  1. 8.5 src/MappingLoader.php \Drupal\gathercontent\MappingLoader::getMapping()

Return the mapping associated with the given Item.

1 call to MappingLoader::getMapping()
MappingLoader::load in src/MappingLoader.php
Cache mappings when loading them.

File

src/MappingLoader.php, line 28

Class

MappingLoader
A static class to return and cache mapping entities.

Namespace

Drupal\gathercontent

Code

public static function getMapping(Item $gcItem) {
  $mappingId = \Drupal::entityQuery('gathercontent_mapping')
    ->condition('gathercontent_project_id', $gcItem->projectId)
    ->condition('gathercontent_template_id', $gcItem->templateId)
    ->execute();
  if (empty($mappingId)) {
    throw new \Exception("Operation failed: Template not mapped.");
  }
  $mappingId = reset($mappingId);
  $mapping = Mapping::load($mappingId);
  if ($mapping === NULL) {
    throw new \Exception("No mapping found with id: {$mappingId}");
  }
  return $mapping;
}