public function ContentEntitySource::getPendingRevisionWithCompositeReferenceField

Returns the source revision if it is a pending revision with an ERR field.

Parameters

\Drupal\tmgmt\JobItemInterface $job_item:

Return value

\Drupal\Core\Entity\ContentEntityInterface|null The source revision entity if it is a pending revision with an ERR field.

1 call to ContentEntitySource::getPendingRevisionWithCompositeReferenceField()
ContentEntitySource::saveTranslation in sources/content/src/Plugin/tmgmt/Source/ContentEntitySource.php
Saves a translation.

File

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

Class

ContentEntitySource
Content entity source plugin controller.

Namespace

Drupal\tmgmt_content\Plugin\tmgmt\Source

Code

public function getPendingRevisionWithCompositeReferenceField(JobItemInterface $job_item) {

  // Get the latest revision of the default translation.

  /** \Drupal\Core\Entity\ContentEntityInterface|null $entity */
  $entity = static::load($job_item
    ->getItemType(), $job_item
    ->getItemId());
  if (!$entity) {
    return NULL;
  }

  // If the given revision is not the default revision, check if there is at
  // least one untranslatable composite entity reference revisions field and
  // fail the validation.
  if (!$entity
    ->isDefaultRevision()) {
    foreach ($entity
      ->getFieldDefinitions() as $definition) {
      if (in_array($definition
        ->getType(), [
        'entity_reference',
        'entity_reference_revisions',
      ]) && !$definition
        ->isTranslatable()) {
        $target_type_id = $definition
          ->getSetting('target_type');
        $entity_type_manager = \Drupal::entityTypeManager();
        if (!$entity_type_manager
          ->hasDefinition($target_type_id)) {
          continue;
        }

        // Check if the target entity type is considered a composite.
        if ($entity_type_manager
          ->getDefinition($target_type_id)
          ->get('entity_revision_parent_type_field')) {
          return $entity;
        }
      }
    }
  }
  return NULL;
}