DefaultConflictDiscovery.php in Conflict 8.2
File
src/ConflictDiscovery/DefaultConflictDiscovery.php
View source
<?php
namespace Drupal\conflict\ConflictDiscovery;
use Drupal\conflict\ConflictTypes;
use Drupal\conflict\Event\EntityConflictDiscoveryEvent;
class DefaultConflictDiscovery extends ConflictDiscoveryBase {
public function discoverConflictsContentEntity(EntityConflictDiscoveryEvent $event) {
$local_entity = $event
->getLocalEntity();
$remote_entity = $event
->getRemoteEntity();
$base_entity = $event
->getBaseEntity();
$langcode = $local_entity
->language()
->getId();
$remote_entity = $remote_entity
->getTranslation($langcode);
$base_entity = $base_entity
->getTranslation($langcode);
$skip_fields = array_flip($local_entity
->getEntityType()
->getRevisionMetadataKeys());
foreach ($local_entity
->getFields() as $field_name => $field_items_local) {
if (isset($skip_fields[$field_name])) {
continue;
}
$field_definition = $field_items_local
->getFieldDefinition();
if ($field_definition
->isReadOnly()) {
continue;
}
$field_items_remote = $remote_entity
->get($field_name);
$field_items_base = $base_entity
->get($field_name);
if (!$field_items_local
->equals($field_items_remote)) {
if (!$field_items_remote
->equals($field_items_base)) {
$conflict_type = $field_items_local
->equals($field_items_base) ? ConflictTypes::CONFLICT_TYPE_REMOTE : ConflictTypes::CONFLICT_TYPE_LOCAL_REMOTE;
$event
->addConflict($field_name, $conflict_type);
}
}
}
}
}