class MappingLoader in GatherContent 8.4
Same name and namespace in other branches
- 8.5 src/MappingLoader.php \Drupal\gathercontent\MappingLoader
A static class to return and cache mapping entities.
Hierarchy
- class \Drupal\gathercontent\MappingLoader
Expanded class hierarchy of MappingLoader
2 files declare their use of MappingLoader
- ContentProcessor.php in src/
Import/ ContentProcess/ ContentProcessor.php - ContentProcessorTest.php in tests/
src/ Kernel/ ContentProcessorTest.php
File
- src/
MappingLoader.php, line 11
Namespace
Drupal\gathercontentView source
class MappingLoader {
protected static $mappings = [];
/**
* Cache mappings when loading them.
*/
public static function load(Item $gcItem) {
if (!isset(static::$mappings[$gcItem->id])) {
static::$mappings[$gcItem->id] = static::getMapping($gcItem);
}
return static::$mappings[$gcItem->id];
}
/**
* Return the mapping associated with the given Item.
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MappingLoader:: |
protected static | property | ||
MappingLoader:: |
public static | function | Return the mapping associated with the given Item. | |
MappingLoader:: |
public static | function | Cache mappings when loading them. |