You are here

public static function PushIntent::pushEntity in CMS Content Sync 2.1.x

Same name and namespace in other branches
  1. 8 src/PushIntent.php \Drupal\cms_content_sync\PushIntent::pushEntity()
  2. 2.0.x src/PushIntent.php \Drupal\cms_content_sync\PushIntent::pushEntity()

Helper function to push an entity and throw errors if anything fails.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to push

string $reason: {@see Flow::PUSH_*}

string $action: {@see ::ACTION_*}

\Drupal\cms_content_sync\Entity\Flow $flow: The flow to be used. If none is given, all flows that may push this entity will be asked to do so for all relevant pools.

\Drupal\cms_content_sync\Entity\Pool $pool: The pool to be used. If not set, all relevant pools for the flow will be used one after another.

bool $return_intent: Return the PushIntent operation instead of executing it. Used to embed entities.

Return value

bool|PushIntent Whether the entity is configured to be pushed or not. if $return_only is given, this will return the serialized entity to embed or NULL.

Throws

\Drupal\cms_content_sync\Exception\SyncException

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Core\Entity\EntityStorageException

\GuzzleHttp\Exception\GuzzleException

6 calls to PushIntent::pushEntity()
CliService::push in src/Cli/CliService.php
Push all entities for a specific flow.
PushEntities::batch in src/Controller/PushEntities.php
Batch push callback used by the following operations:
PushIntent::embedForFlowAndPool in src/PushIntent.php
Push the provided entity along with the processed entity by embedding it right into the current entity. This means the embedded entity can't be used outside of it's parent entity in any way. This is used for field collections right now.
PushIntent::pushEntityFromUi in src/PushIntent.php
Helper function to push an entity and display the user the results. If you want to make changes programmatically, use ::pushEntity() instead.
PushIntent::pushReference in src/PushIntent.php

... See full list

File

src/PushIntent.php, line 600

Class

PushIntent
Class PushIntent.

Namespace

Drupal\cms_content_sync

Code

public static function pushEntity(EntityInterface $entity, $reason, $action, Flow $flow = null, Pool $pool = null, $return_intent = false) {
  if (!$flow) {
    $flows = self::getFlowsForEntity($entity, $reason, $action);
    if (!count($flows)) {
      return false;
    }
    $result = false;
    foreach ($flows as $flow) {
      if ($return_intent) {
        $result = self::pushEntity($entity, $reason, $action, $flow, null, true);
        if ($result) {
          return $result;
        }
      }
      else {
        $result |= self::pushEntity($entity, $reason, $action, $flow);
      }
    }
    return $result;
  }
  if (!$pool) {
    $pools = $flow
      ->getController()
      ->getPoolsToPushTo($entity, $reason, $action, true);
    $result = false;
    foreach ($pools as $pool) {
      $infos = EntityStatus::getInfosForEntity($entity
        ->getEntityTypeId(), $entity
        ->uuid(), [
        'pool' => $pool
          ->label(),
      ]);
      $cancel = false;
      foreach ($infos as $info) {
        if (!$info
          ->getFlow()) {
          continue;
        }
        if (!$info
          ->getLastPull()) {
          continue;
        }
        $config = $info
          ->getFlow()
          ->getController()
          ->getEntityTypeConfig($entity
          ->getEntityTypeId(), $entity
          ->bundle())['import_updates'];
        if (in_array($config, [
          PullIntent::PULL_UPDATE_FORCE_AND_FORBID_EDITING,
          PullIntent::PULL_UPDATE_FORCE_UNLESS_OVERRIDDEN,
        ])) {
          $cancel = true;
          break;
        }
      }
      if ($cancel) {
        continue;
      }
      if ($return_intent) {
        $result = self::pushEntity($entity, $reason, $action, $flow, $pool, true);
        if ($result) {
          return $result;
        }
      }
      else {
        $result |= self::pushEntity($entity, $reason, $action, $flow, $pool);
      }
    }
    return $result;
  }
  $intent = new PushIntent($flow, $pool, $reason, $action, $entity);
  return $intent
    ->execute($return_intent);
}