Error message

  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).
  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).

protected function ConfigSource::getMapper

Gets the mapper.

Parameters

\Drupal\tmgmt\JobItemInterface $job_item: Gets a job item as a parameter.

Return value

\Drupal\config_translation\ConfigMapperInterface $config_mapper Returns the config mapper.

Throws

\Drupal\tmgmt\TMGMTException If there is no entity, throws an exception.

4 calls to ConfigSource::getMapper()
ConfigSource::getData in sources/tmgmt_config/src/Plugin/tmgmt/Source/ConfigSource.php
Implements TMGMTEntitySourcePluginController::getData().
ConfigSource::getSourceLangCode in sources/tmgmt_config/src/Plugin/tmgmt/Source/ConfigSource.php
Gets language code of the job item source.
ConfigSource::getUrl in sources/tmgmt_config/src/Plugin/tmgmt/Source/ConfigSource.php
Returns the Uri for this job item.
ConfigSource::saveTranslation in sources/tmgmt_config/src/Plugin/tmgmt/Source/ConfigSource.php
Saves a translation.

File

sources/tmgmt_config/src/Plugin/tmgmt/Source/ConfigSource.php, line 146

Class

ConfigSource
Content entity source plugin controller.

Namespace

Drupal\tmgmt_config\Plugin\tmgmt\Source

Code

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;
}