Skip to content

Instantly share code, notes, and snippets.

@neclimdul
Created September 22, 2021 20:24
Show Gist options
  • Save neclimdul/9719e21fc7fe162ca8d3080d9aad362f to your computer and use it in GitHub Desktop.
Save neclimdul/9719e21fc7fe162ca8d3080d9aad362f to your computer and use it in GitHub Desktop.
<?php
namespace Drupal\my_custom;
use Drupal\my_custom\Normalizer\FileEntityNormalizer;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
/**
* Remove file normalizers that are causing problems.
*/
class TestServiceProvider extends ServiceProviderBase {
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container) {
// Make sure definition exists before we replace. It might not in certain
// testing conditions.
if ($container->has('serializer.normalizer.entity.file_entity')) {
// Replace file normalizer with one that doesn't include actual files.
$service_definition = new Definition(FileEntityNormalizer::class, [
new Reference('hal.link_manager'),
new Reference('entity.manager'),
new Reference('module_handler'),
]);
// The priority must be higher than that of
// serializer.normalizer.file_entity.hal in hal.services.yml.
$service_definition->addTag('normalizer', ['priority' => 30]);
$container->setDefinition('serializer.normalizer.entity.file_entity', $service_definition);
}
}
}
@neclimdul
Copy link
Author

There are two d9 upgrade failures here. I don't know what of them are testable its an interesting edge case for upgrade failures.

  1. entity.manager deprecated then removed.
  2. argument list doesn't match the constructor argument list in d9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment