You are here

protected function EntityReferenceRevisionsOrphanPurger::isValidParent in Entity Reference Revisions 8

Checks if the parent type/field is a valid combination that can be queried.

Parameters

string $parent_type: Parent entity type ID.

string $parent_field_name: Parent field name.

Return value

int static::PARENT_VALID, static::PARENT_INVALID_SKIP or static::PARENT_INVALID_DELETE.

1 call to EntityReferenceRevisionsOrphanPurger::isValidParent()
EntityReferenceRevisionsOrphanPurger::isUsed in src/EntityReferenceRevisionsOrphanPurger.php
Checks if the composite entity is used.

File

src/EntityReferenceRevisionsOrphanPurger.php, line 351

Class

EntityReferenceRevisionsOrphanPurger
Manages orphan composite revision deletion.

Namespace

Drupal\entity_reference_revisions

Code

protected function isValidParent($parent_type, $parent_field_name) {

  // There is not certainty that this revision is not used because we do not
  // know what to query for if the parent fields are empty.
  if ($parent_type == NULL) {
    return static::PARENT_INVALID_SKIP;
  }
  if (isset($this->validParents[$parent_type][$parent_field_name])) {
    return $this->validParents[$parent_type][$parent_field_name];
  }
  $status = static::PARENT_VALID;

  // If the parent type does not exist anymore, the composite is not used.
  if (!$this->entityTypeManager
    ->hasDefinition($parent_type)) {
    $status = static::PARENT_INVALID_DELETE;
  }
  else {
    $parent_field_definitions = $this->entityFieldManager
      ->getFieldStorageDefinitions($parent_type);
    if (!isset($parent_field_definitions[$parent_field_name])) {
      $status = static::PARENT_INVALID_DELETE;
    }
    elseif (empty($parent_field_definitions[$parent_field_name]
      ->getSchema()['columns']['target_revision_id'])) {
      $status = static::PARENT_INVALID_SKIP;
    }
  }
  $this->validParents[$parent_type][$parent_field_name] = $status;
  return $status;
}