You are here

public function FileEntityNormalizer::supportsDenormalization in Replication 8

Same name and namespace in other branches
  1. 8.2 src/Normalizer/FileEntityNormalizer.php \Drupal\replication\Normalizer\FileEntityNormalizer::supportsDenormalization()

Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization()

This class doesn't implement DenormalizerInterface, but most of its child classes do. Therefore, this method is implemented at this level to reduce code duplication.

Overrides NormalizerBase::supportsDenormalization

File

src/Normalizer/FileEntityNormalizer.php, line 100

Class

FileEntityNormalizer

Namespace

Drupal\replication\Normalizer

Code

public function supportsDenormalization($data, $type, $format = NULL) {

  // We need to accept both FileInterface and ContentEntityInterface classes.
  // File entities are treated as standard content entities.
  if (in_array($type, [
    'Drupal\\Core\\Entity\\ContentEntityInterface',
    'Drupal\\file\\FileInterface',
  ], TRUE)) {

    // If a document has _attachment then we assume it's a file entity.
    if (!empty($data['@attachment'])) {
      return TRUE;
    }
  }
  return FALSE;
}