You are here

public function ContentImporter::validateEntity in Content Synchronization 8.2

Same name and namespace in other branches
  1. 3.0.x src/Importer/ContentImporter.php \Drupal\content_sync\Importer\ContentImporter::validateEntity()
1 call to ContentImporter::validateEntity()
ContentImporter::syncEntity in src/Importer/ContentImporter.php
Synchronize a given entity.

File

src/Importer/ContentImporter.php, line 297

Class

ContentImporter

Namespace

Drupal\content_sync\Importer

Code

public function validateEntity(ContentEntityInterface $entity) {
  $reflection = new \ReflectionClass($entity);
  $valid = TRUE;
  if ($reflection
    ->implementsInterface('\\Drupal\\user\\UserInterface')) {
    $validations = $entity
      ->validate();
    if (count($validations)) {

      /**
       * @var ConstraintViolation $validation
       */
      foreach ($validations as $validation) {
        if (!empty($this
          ->getContext()['skipped_constraints']) && in_array(get_class($validation
          ->getConstraint()), $this
          ->getContext()['skipped_constraints'])) {
          continue;
        }
        $valid = FALSE;
        \Drupal::logger('content_sync')
          ->error($validation
          ->getMessage());
      }
    }
  }
  return $valid;
}