You are here

protected function ReplicateContent::doExecute in Workspace 8

Replicate content from active Workspace to it's upstream.

File

src/Plugin/RulesAction/ReplicateContent.php, line 85

Class

ReplicateContent
Provides a 'Save entity' action.

Namespace

Drupal\workspace\Plugin\RulesAction

Code

protected function doExecute(EntityInterface $entity) {

  /** @var \Drupal\multiversion\Entity\Workspace $workspace */
  $workspace = $this->multiversionManager
    ->isSupportedEntityType($entity
    ->getEntityType()) ? $entity
    ->get('workspace')->entity : $this->workspaceManager
    ->getActiveWorkspace();
  $source = $this
    ->getPointerToWorkspace($workspace);

  /** @var \Drupal\workspace\WorkspacePointerInterface $upstream */
  $upstream = $workspace
    ->get('upstream')->entity;

  // Derive a replication task from the source Workspace.
  $task = $this->replicatorManager
    ->getTask($workspace, 'push_replication_settings');

  /** @var \Drupal\replication\Entity\ReplicationLogInterface $result */
  $result = $this->replicatorManager
    ->replicate($source, $upstream, $task);
  if ($result
    ->get('ok')->value == TRUE) {
    drupal_set_message($this
      ->t('Content replicated from workspace @source to workspace @upstream.', [
      '@source' => $workspace
        ->label(),
      '@upstream' => $upstream
        ->label(),
    ]));
  }
  else {
    drupal_set_message($this
      ->t('Error replicating content.'));
  }
}