3 namespace Drupal\hal\Normalizer;
5 use Drupal\Core\Config\ConfigFactoryInterface;
6 use Drupal\Core\Entity\EntityManagerInterface;
7 use Drupal\Core\Extension\ModuleHandlerInterface;
8 use Drupal\hal\LinkManager\LinkManagerInterface;
11 * Converts the Drupal entity object structure to a HAL array structure.
13 * @deprecated in Drupal 8.5.0, to be removed before Drupal 9.0.0.
15 class FileEntityNormalizer extends ContentEntityNormalizer {
18 * The interface or class that this Normalizer supports.
22 protected $supportedInterfaceOrClass = 'Drupal\file\FileInterface';
27 * @var \GuzzleHttp\ClientInterface
29 protected $httpClient;
32 * The HAL settings config.
34 * @var \Drupal\Core\Config\ImmutableConfig
36 protected $halSettings;
39 * Constructs a FileEntityNormalizer object.
41 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
43 * @param \Drupal\hal\LinkManager\LinkManagerInterface $link_manager
44 * The hypermedia link manager.
45 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
47 * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
50 public function __construct(EntityManagerInterface $entity_manager, LinkManagerInterface $link_manager, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory) {
51 parent::__construct($link_manager, $entity_manager, $module_handler);
53 $this->halSettings = $config_factory->get('hal.settings');
59 public function normalize($entity, $format = NULL, array $context = []) {
60 $data = parent::normalize($entity, $format, $context);
62 $this->addCacheableDependency($context, $this->halSettings);
64 if ($this->halSettings->get('bc_file_uri_as_url_normalizer')) {
65 // Replace the file url with a full url for the file.
66 $data['uri'][0]['value'] = $this->getEntityUri($entity);