You are here

public function ReplicatorManager::getTask in Workspace 8

Derives a replication task from an entity with replication settings.

This can be used with a Workspace using the 'push_replication_settings' and 'pull_replication_settings' fields.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to derive the replication task from.

string $field_name: The field name that references a ReplicationSettings config entity.

Return value

\Drupal\replication\ReplicationTask\ReplicationTaskInterface A replication task that can be passed to a replicator.

Throws

\Symfony\Component\Console\Exception\LogicException The replication settings field does not exist on the entity.

1 call to ReplicatorManager::getTask()
ReplicatorManager::replicate in src/ReplicatorManager.php
Perform the replication from the source to target workspace.

File

src/ReplicatorManager.php, line 167

Class

ReplicatorManager
Provides the Replicator manager.

Namespace

Drupal\workspace

Code

public function getTask(EntityInterface $entity, $field_name) {
  $task = new ReplicationTask();
  $items = $entity
    ->get($field_name);
  if (!$items instanceof EntityReferenceFieldItemListInterface) {
    throw new LogicException('Replication settings field does not exist.');
  }
  $referenced_entities = $items
    ->referencedEntities();
  if (count($referenced_entities) > 0) {
    $task
      ->setFilter($referenced_entities[0]
      ->getFilterId());
    $task
      ->setParameters($referenced_entities[0]
      ->getParameters());
  }
  return $task;
}