ConflictResolverManager.php in Conflict 8.2
File
src/ConflictResolver/ConflictResolverManager.php
View source
<?php
namespace Drupal\conflict\ConflictResolver;
use Drupal\conflict\Event\EntityConflictDiscoveryEvent;
use Drupal\conflict\Event\EntityConflictEvents;
use Drupal\conflict\Event\EntityConflictResolutionEvent;
use Drupal\Core\Entity\EntityInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\ParameterBag;
class ConflictResolverManager implements ConflictResolverManagerInterface {
protected $eventDispatcher;
public function __construct(EventDispatcherInterface $event_dispatcher) {
$this->eventDispatcher = $event_dispatcher;
}
public function resolveConflicts(EntityInterface $local, EntityInterface $remote, EntityInterface $base, EntityInterface $result = NULL, ParameterBag $context = NULL, array $conflicts = NULL) : array {
$conflicts = $conflicts ?? $this
->getConflicts($local, $remote, $base, $context);
if ($conflicts) {
$result = $result ?? $local;
$event = new EntityConflictResolutionEvent($local, $remote, $base, $result, $conflicts, $context);
$this->eventDispatcher
->dispatch(EntityConflictEvents::ENTITY_CONFLICT_RESOLVE, $event);
$conflicts = $event
->getConflicts();
}
return $conflicts;
}
public function getConflicts(EntityInterface $local, EntityInterface $remote, EntityInterface $base, ParameterBag $context = NULL) : array {
$event = new EntityConflictDiscoveryEvent($local, $remote, $base, $context);
$this->eventDispatcher
->dispatch(EntityConflictEvents::ENTITY_CONFLICT_DISCOVERY, $event);
return $event
->getConflicts();
}
}