Returns the source revision if it is a pending revision with an ERR field.
\Drupal\tmgmt\JobItemInterface $job_item:
\Drupal\Core\Entity\ContentEntityInterface|null The source revision entity if it is a pending revision with an ERR field.
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;
}