You are here

public function ContentEntitySource::getType in Translation Management Tool 8

Returns the type of a job item.

Parameters

\Drupal\tmgmt\JobItemInterface $job_item: The job item.

Return value

string A type that describes the job item.

Overrides SourcePluginBase::getType

File

sources/content/src/Plugin/tmgmt/Source/ContentEntitySource.php, line 437

Class

ContentEntitySource
Content entity source plugin controller.

Namespace

Drupal\tmgmt_content\Plugin\tmgmt\Source

Code

public function getType(JobItemInterface $job_item) {
  if ($entity = $this
    ->getEntity($job_item)) {
    $bundles = \Drupal::service('entity_type.bundle.info')
      ->getBundleInfo($job_item
      ->getItemType());
    $entity_type = $entity
      ->getEntityType();
    $bundle = $entity
      ->bundle();

    // Display entity type and label if we have one and the bundle isn't
    // the same as the entity type.
    if (isset($bundles[$bundle]) && $bundle != $job_item
      ->getItemType()) {
      return t('@type (@bundle)', array(
        '@type' => $entity_type
          ->getLabel(),
        '@bundle' => $bundles[$bundle]['label'],
      ));
    }

    // Otherwise just display the entity type label.
    return $entity_type
      ->getLabel();
  }
}