You are here

public function Flow::canPushEntity in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.0.x src/Entity/Flow.php \Drupal\cms_content_sync\Entity\Flow::canPushEntity()

Ask this Flow whether or not it can push the given entity.

Parameters

string|string[] $reason:

string $action:

null|Pool $pool:

Return value

bool

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

1 call to Flow::canPushEntity()
Flow::getPoolsToPushTo in src/Entity/Flow.php
Get a list of all pools that are used for pushing this entity, either automatically or manually selected.

File

src/Entity/Flow.php, line 419

Class

Flow
Defines the "Content Sync - Flow" entity.

Namespace

Drupal\cms_content_sync\Entity

Code

public function canPushEntity(EntityInterface $entity, $reason, $action = SyncIntent::ACTION_CREATE, $pool = null) {
  $infos = $entity
    ->uuid() ? EntityStatus::getInfosForEntity($entity
    ->getEntityTypeId(), $entity
    ->uuid()) : [];

  // Fresh entity- no pool restriction.
  if (!count($infos) || null !== $pool) {
    return $this
      ->canPushEntityType($entity
      ->getEntityTypeId(), $entity
      ->bundle(), $reason, $action, $pool);
  }

  // If the entity has been pulled or pushed before, only the Flows that support the pools that were assigned
  // are relevant. So we filter out any Flows here that don't support any of the assigned pools.
  foreach ($infos as $info) {
    if ($this
      ->canPushEntityType($entity
      ->getEntityTypeId(), $entity
      ->bundle(), $reason, $action, $info
      ->getPool())) {
      return true;
    }
  }

  // Flow config may have changed so status entities exist but now they no longer push the entity. In this case we
  // fall back into the behavior as if the entity was new (see above)
  return $this
    ->canPushEntityType($entity
    ->getEntityTypeId(), $entity
    ->bundle(), $reason, $action, $pool);
}