You are here

public function ContentEntitySource::shouldCreateContinuousItem in Translation Management Tool 8

Checks whether the continuous job item should be created.

Parameters

\Drupal\tmgmt\Entity\Job $job: Continuous job.

string $plugin: The plugin name.

string $item_type: The source item type.

string $item_id: The source item id.

Return value

bool TRUE if continuous job item should be created, FALSE if not.

Overrides ContinuousSourceInterface::shouldCreateContinuousItem

File

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

Class

ContentEntitySource
Content entity source plugin controller.

Namespace

Drupal\tmgmt_content\Plugin\tmgmt\Source

Code

public function shouldCreateContinuousItem(Job $job, $plugin, $item_type, $item_id) {
  $continuous_settings = $job
    ->getContinuousSettings();
  $entity = static::load($item_type, $item_id, $job
    ->getSourceLangcode());
  $translation_manager = \Drupal::service('content_translation.manager');
  $translation = $entity
    ->hasTranslation($job
    ->getTargetLangcode()) ? $entity
    ->getTranslation($job
    ->getTargetLangcode()) : NULL;
  $metadata = isset($translation) ? $translation_manager
    ->getTranslationMetadata($translation) : NULL;

  // If a translation exists and is not marked as outdated, no new job items
  // needs to be created.
  if (isset($translation) && !$metadata
    ->isOutdated()) {
    return FALSE;
  }
  else {
    if ($entity && $entity
      ->getEntityType()
      ->hasKey('bundle')) {

      // The entity type has bundles, check both the entity type setting and
      // the bundle.
      if (!empty($continuous_settings[$plugin][$item_type]['bundles'][$entity
        ->bundle()]) && !empty($continuous_settings[$plugin][$item_type]['enabled'])) {
        return TRUE;
      }
    }
    elseif (!empty($continuous_settings[$plugin][$item_type]['enabled'])) {
      return TRUE;
    }
  }
  return FALSE;
}