Gets the mapper.
\Drupal\tmgmt\JobItemInterface $job_item: Gets a job item as a parameter.
\Drupal\config_translation\ConfigMapperInterface $config_mapper Returns the config mapper.
\Drupal\tmgmt\TMGMTException If there is no entity, throws an exception.
protected function getMapper(JobItemInterface $job_item) {
$config_mapper = $this->configMapperManager
->createInstance($this
->getMapperId($job_item));
if ($job_item
->getItemType() != static::SIMPLE_CONFIG) {
/** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type */
$entity_type = $this->entityTypeManager
->getDefinition($config_mapper
->getType());
$pos = strpos($job_item
->getItemId(), $entity_type
->getConfigPrefix());
if ($pos !== FALSE) {
$entity_id = str_replace($entity_type
->getConfigPrefix() . '.', '', $job_item
->getItemId());
}
else {
throw new TMGMTException(t('Item ID does not contain the full config object name.'));
}
$entity = $this->entityTypeManager
->getStorage($config_mapper
->getType())
->load($entity_id);
if (!$entity) {
throw new TMGMTException(t('Unable to load entity %type with id %id', array(
'%type' => $job_item
->getItemType(),
'%id' => $entity_id,
)));
}
$config_mapper
->setEntity($entity);
}
return $config_mapper;
}