Skip to content

Commit

Permalink
Replace file_create_url() call in FileEntityNormalizer.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-vessey committed Sep 28, 2023
1 parent bae8c1c commit 381e90c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion content_sync.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ services:
- { name: normalizer, priority: 6 }
content_sync.normalizer.file_entity:
class: Drupal\content_sync\Normalizer\FileEntityNormalizer
arguments: ['@entity_type.manager', '@entity_type.repository', '@entity_field.manager', '@entity_type.bundle.info', '@entity.repository', '@plugin.manager.sync_normalizer_decorator', '@file_system']
arguments: ['@entity_type.manager', '@entity_type.repository', '@entity_field.manager', '@entity_type.bundle.info', '@entity.repository', '@plugin.manager.sync_normalizer_decorator', '@file_system', '@file_url_generator']
tags:
- { name: normalizer, priority: 7 }
content_sync.normalizer.user_entity:
Expand Down
30 changes: 20 additions & 10 deletions src/Normalizer/FileEntityNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\File\FileUrlGeneratorInterface;

/**
* Adds the file URI to embedded file entities.
Expand All @@ -31,19 +32,28 @@ class FileEntityNormalizer extends ContentEntityNormalizer {
protected $fileSystem;

/**
* FileEntityNormalizer constructor.
* File URL generator service.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Entity\EntityTypeRepositoryInterface $entity_type_repository
* The entity type repository.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
* @param \Drupal\content_sync\Plugin\SyncNormalizerDecoratorManager $decorator_manager
* @var \Drupal\Core\File\FileUrlGeneratorInterface
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeRepositoryInterface $entity_type_repository, EntityFieldManagerInterface $entity_field_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityRepositoryInterface $entity_repository, SyncNormalizerDecoratorManager $decorator_manager, FileSystemInterface $file_system) {
protected FileUrlGeneratorInterface $fileUrlGenerator;

/**
* Constructor.
*/
public function __construct(
EntityTypeManagerInterface $entity_type_manager,
EntityTypeRepositoryInterface $entity_type_repository,
EntityFieldManagerInterface $entity_field_manager,
EntityTypeBundleInfoInterface $entity_type_bundle_info,
EntityRepositoryInterface $entity_repository,
SyncNormalizerDecoratorManager $decorator_manager,
FileSystemInterface $file_system,
FileUrlGeneratorInterface $file_url_generator
) {
parent::__construct($entity_type_manager, $entity_type_repository, $entity_field_manager, $entity_type_bundle_info, $entity_repository, $decorator_manager);
$this->fileSystem = $file_system;
$this->fileUrlGenerator = $file_url_generator;
}

/**
Expand Down Expand Up @@ -75,7 +85,7 @@ public function denormalize($data, $class, $format = NULL, array $serializer_con
$data['uri'] = [
[
'value' => $uri,
'url' => str_replace($GLOBALS['base_url'], '', file_create_url($uri))
'url' => str_replace($GLOBALS['base_url'], '', $this->fileUrlGenerator->generateString($uri))
]
];

Expand Down

0 comments on commit 381e90c

Please sign in to comment.