diff --git a/core/modules/file/src/Upload/RawUploadedFile.php b/core/modules/file/src/Upload/RawUploadedFile.php index ac992c6544..fda74770ac 100644 --- a/core/modules/file/src/Upload/RawUploadedFile.php +++ b/core/modules/file/src/Upload/RawUploadedFile.php @@ -107,14 +107,14 @@ public function getRealPath() { /** * {@inheritdoc} */ - public function getPathname() { + public function getPathname(): string { return parent::getPathname(); } /** * {@inheritdoc} */ - public function getFilename() { + public function getFilename(): string { return parent::getFilename(); } diff --git a/core/modules/jsonapi/jsonapi.info.yml b/core/modules/jsonapi/jsonapi.info.yml index 5296de6b25..4d9257c4fc 100644 --- a/core/modules/jsonapi/jsonapi.info.yml +++ b/core/modules/jsonapi/jsonapi.info.yml @@ -6,4 +6,3 @@ version: VERSION configure: jsonapi.settings dependencies: - drupal:serialization - - drupal:file diff --git a/core/modules/jsonapi/jsonapi.services.yml b/core/modules/jsonapi/jsonapi.services.yml index e08720c657..0c032cfc3f 100644 --- a/core/modules/jsonapi/jsonapi.services.yml +++ b/core/modules/jsonapi/jsonapi.services.yml @@ -188,19 +188,6 @@ services: - '@jsonapi.serializer' - '@datetime.time' - '@current_user' - jsonapi.file_upload: - class: Drupal\jsonapi\Controller\FileUpload - arguments: - - '@current_user' - - '@entity_field.manager' - - '@jsonapi.file.uploader.field' - - '@http_kernel' - - '@file.field_upload_handler' - - '@file.field_definition_resolver' - - '@file.upload_access_checker' - - '@file.upload_filename_extractor' - - '@file.raw_file_uploader' - - '@logger.channel.file' # Event subscribers. jsonapi.custom_query_parameter_names_validator.subscriber: diff --git a/core/modules/jsonapi/src/JsonapiServiceProvider.php b/core/modules/jsonapi/src/JsonapiServiceProvider.php index e3b0f6d0cc..8cced88db2 100644 --- a/core/modules/jsonapi/src/JsonapiServiceProvider.php +++ b/core/modules/jsonapi/src/JsonapiServiceProvider.php @@ -6,16 +6,17 @@ use Drupal\Core\DependencyInjection\ServiceModifierInterface; use Drupal\Core\DependencyInjection\ServiceProviderInterface; use Drupal\Core\StackMiddleware\NegotiationMiddleware; +use Drupal\jsonapi\Controller\FileUpload; use Drupal\jsonapi\DependencyInjection\Compiler\RegisterSerializationClassesCompilerPass; +use Symfony\Component\DependencyInjection\Reference; /** * Adds 'api_json' as known format and prevents its use in the REST module. * - * @internal JSON:API maintains no PHP API since its API is the HTTP API. This - * class may change at any time and this will break any dependencies on it. - * * @see https://www.drupal.org/project/drupal/issues/3032787 * @see jsonapi.api.php + * @internal JSON:API maintains no PHP API since its API is the HTTP API. This + * class may change at any time and this will break any dependencies on it. */ class JsonapiServiceProvider implements ServiceModifierInterface, ServiceProviderInterface { @@ -23,7 +24,8 @@ class JsonapiServiceProvider implements ServiceModifierInterface, ServiceProvide * {@inheritdoc} */ public function alter(ContainerBuilder $container) { - if ($container->has('http_middleware.negotiation') && is_a($container->getDefinition('http_middleware.negotiation')->getClass(), NegotiationMiddleware::class, TRUE)) { + if ($container->has('http_middleware.negotiation') && is_a($container->getDefinition('http_middleware.negotiation') + ->getClass(), NegotiationMiddleware::class, TRUE)) { // @see http://www.iana.org/assignments/media-types/application/vnd.api+json $container->getDefinition('http_middleware.negotiation') ->addMethodCall('registerFormat', [ @@ -38,6 +40,21 @@ public function alter(ContainerBuilder $container) { */ public function register(ContainerBuilder $container) { $container->addCompilerPass(new RegisterSerializationClassesCompilerPass()); + // Only register file_upload service if the file module is enabled. + $modules = $container->getParameter('container.modules'); + if (isset($modules['file'])) { + $container->register('jsonapi.file_upload', FileUpload::class) + ->addArgument(new Reference('current_user')) + ->addArgument(new Reference('entity_field.manager')) + ->addArgument(new Reference('jsonapi.file.uploader.field')) + ->addArgument(new Reference('http_kernel')) + ->addArgument(new Reference('file.field_upload_handler')) + ->addArgument(new Reference('file.field_definition_resolver')) + ->addArgument(new Reference('file.upload_access_checker')) + ->addArgument(new Reference('file.upload_filename_extractor')) + ->addArgument(new Reference('file.raw_file_uploader')) + ->addArgument(new Reference('logger.channel.file')); + } } } diff --git a/core/modules/jsonapi/tests/src/Functional/EntryPointTest.php b/core/modules/jsonapi/tests/src/Functional/EntryPointTest.php index 815bee4e6f..22f5da27cc 100644 --- a/core/modules/jsonapi/tests/src/Functional/EntryPointTest.php +++ b/core/modules/jsonapi/tests/src/Functional/EntryPointTest.php @@ -27,7 +27,6 @@ class EntryPointTest extends BrowserTestBase { 'node', 'jsonapi', 'basic_auth', - 'file', ]; /** diff --git a/core/modules/jsonapi/tests/src/Functional/ExternalNormalizersTest.php b/core/modules/jsonapi/tests/src/Functional/ExternalNormalizersTest.php index a0af7578a8..3214ca4301 100644 --- a/core/modules/jsonapi/tests/src/Functional/ExternalNormalizersTest.php +++ b/core/modules/jsonapi/tests/src/Functional/ExternalNormalizersTest.php @@ -47,7 +47,6 @@ class ExternalNormalizersTest extends BrowserTestBase { protected static $modules = [ 'jsonapi', 'entity_test', - 'file', ]; /** diff --git a/core/modules/jsonapi/tests/src/Functional/InternalEntitiesTest.php b/core/modules/jsonapi/tests/src/Functional/InternalEntitiesTest.php index f43d607466..032c49698e 100644 --- a/core/modules/jsonapi/tests/src/Functional/InternalEntitiesTest.php +++ b/core/modules/jsonapi/tests/src/Functional/InternalEntitiesTest.php @@ -28,7 +28,6 @@ class InternalEntitiesTest extends BrowserTestBase { 'jsonapi', 'entity_test', 'serialization', - 'file', ]; /** diff --git a/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php b/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php index 01aae8e0dc..d7dae50d0c 100644 --- a/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php +++ b/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php @@ -65,7 +65,6 @@ abstract class ResourceTestBase extends BrowserTestBase { 'rest_test', 'jsonapi_test_field_access', 'text', - 'file', ]; /** diff --git a/core/modules/jsonapi/tests/src/Functional/RestJsonApiUnsupported.php b/core/modules/jsonapi/tests/src/Functional/RestJsonApiUnsupported.php index 90722f8ede..e0a79f3f56 100644 --- a/core/modules/jsonapi/tests/src/Functional/RestJsonApiUnsupported.php +++ b/core/modules/jsonapi/tests/src/Functional/RestJsonApiUnsupported.php @@ -22,7 +22,7 @@ class RestJsonApiUnsupported extends ResourceTestBase { /** * {@inheritdoc} */ - protected static $modules = ['jsonapi', 'node', 'file']; + protected static $modules = ['jsonapi', 'node']; /** * {@inheritdoc} diff --git a/core/modules/jsonapi/tests/src/Kernel/Context/FieldResolverTest.php b/core/modules/jsonapi/tests/src/Kernel/Context/FieldResolverTest.php index 9cddbe0db0..fc274647fa 100644 --- a/core/modules/jsonapi/tests/src/Kernel/Context/FieldResolverTest.php +++ b/core/modules/jsonapi/tests/src/Kernel/Context/FieldResolverTest.php @@ -24,7 +24,6 @@ class FieldResolverTest extends JsonapiKernelTestBase { 'field', 'text', 'user', - 'file', ]; /** diff --git a/core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php b/core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php index ec56dd9f29..859cb80599 100644 --- a/core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php +++ b/core/modules/jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php @@ -46,7 +46,6 @@ class EntityResourceTest extends JsonapiKernelTestBase { 'serialization', 'system', 'user', - 'file', ]; /** diff --git a/core/modules/jsonapi/tests/src/Kernel/EventSubscriber/ResourceObjectNormalizerCacherTest.php b/core/modules/jsonapi/tests/src/Kernel/EventSubscriber/ResourceObjectNormalizerCacherTest.php index 67937d79b1..e715edc47e 100644 --- a/core/modules/jsonapi/tests/src/Kernel/EventSubscriber/ResourceObjectNormalizerCacherTest.php +++ b/core/modules/jsonapi/tests/src/Kernel/EventSubscriber/ResourceObjectNormalizerCacherTest.php @@ -27,7 +27,6 @@ class ResourceObjectNormalizerCacherTest extends KernelTestBase { 'serialization', 'jsonapi', 'user', - 'file', ]; /** diff --git a/core/modules/jsonapi/tests/src/Kernel/Normalizer/FieldItemNormalizerTest.php b/core/modules/jsonapi/tests/src/Kernel/Normalizer/FieldItemNormalizerTest.php index f290f971db..cb40e712b5 100644 --- a/core/modules/jsonapi/tests/src/Kernel/Normalizer/FieldItemNormalizerTest.php +++ b/core/modules/jsonapi/tests/src/Kernel/Normalizer/FieldItemNormalizerTest.php @@ -26,7 +26,6 @@ class FieldItemNormalizerTest extends JsonapiKernelTestBase { 'link', 'entity_test', 'serialization', - 'file', ]; /** diff --git a/core/modules/jsonapi/tests/src/Kernel/Normalizer/LinkCollectionNormalizerTest.php b/core/modules/jsonapi/tests/src/Kernel/Normalizer/LinkCollectionNormalizerTest.php index 8dc4cb8ebb..4282b62947 100644 --- a/core/modules/jsonapi/tests/src/Kernel/Normalizer/LinkCollectionNormalizerTest.php +++ b/core/modules/jsonapi/tests/src/Kernel/Normalizer/LinkCollectionNormalizerTest.php @@ -53,7 +53,6 @@ class LinkCollectionNormalizerTest extends KernelTestBase { 'serialization', 'system', 'user', - 'file', ]; /** diff --git a/core/modules/jsonapi/tests/src/Kernel/ResourceType/RelatedResourceTypesTest.php b/core/modules/jsonapi/tests/src/Kernel/ResourceType/RelatedResourceTypesTest.php index f6d56d70a9..3ee33a9c6e 100644 --- a/core/modules/jsonapi/tests/src/Kernel/ResourceType/RelatedResourceTypesTest.php +++ b/core/modules/jsonapi/tests/src/Kernel/ResourceType/RelatedResourceTypesTest.php @@ -25,7 +25,6 @@ class RelatedResourceTypesTest extends JsonapiKernelTestBase { 'system', 'user', 'field', - 'file', ]; /** diff --git a/core/modules/jsonapi/tests/src/Kernel/ResourceType/ResourceTypeRepositoryTest.php b/core/modules/jsonapi/tests/src/Kernel/ResourceType/ResourceTypeRepositoryTest.php index 41acfe54b9..5503967191 100644 --- a/core/modules/jsonapi/tests/src/Kernel/ResourceType/ResourceTypeRepositoryTest.php +++ b/core/modules/jsonapi/tests/src/Kernel/ResourceType/ResourceTypeRepositoryTest.php @@ -25,7 +25,6 @@ class ResourceTypeRepositoryTest extends JsonapiKernelTestBase { 'system', 'user', 'jsonapi_test_resource_type_building', - 'file', ]; /** diff --git a/core/modules/jsonapi/tests/src/Kernel/Revisions/VersionNegotiatorTest.php b/core/modules/jsonapi/tests/src/Kernel/Revisions/VersionNegotiatorTest.php index eb87fc1dfe..ce8fabf3df 100644 --- a/core/modules/jsonapi/tests/src/Kernel/Revisions/VersionNegotiatorTest.php +++ b/core/modules/jsonapi/tests/src/Kernel/Revisions/VersionNegotiatorTest.php @@ -64,7 +64,6 @@ class VersionNegotiatorTest extends JsonapiKernelTestBase { 'serialization', 'system', 'user', - 'file', ]; /** diff --git a/core/modules/jsonapi/tests/src/Kernel/Serializer/SerializerTest.php b/core/modules/jsonapi/tests/src/Kernel/Serializer/SerializerTest.php index 54cbc83fd9..b55b25b98f 100644 --- a/core/modules/jsonapi/tests/src/Kernel/Serializer/SerializerTest.php +++ b/core/modules/jsonapi/tests/src/Kernel/Serializer/SerializerTest.php @@ -33,7 +33,6 @@ class SerializerTest extends JsonapiKernelTestBase { 'text', 'filter', 'jsonapi_test_data_type', - 'file', ]; /** diff --git a/core/tests/Drupal/KernelTests/Core/Extension/ModuleConfigureRouteTest.php b/core/tests/Drupal/KernelTests/Core/Extension/ModuleConfigureRouteTest.php index 0d3609d931..e81a11de31 100644 --- a/core/tests/Drupal/KernelTests/Core/Extension/ModuleConfigureRouteTest.php +++ b/core/tests/Drupal/KernelTests/Core/Extension/ModuleConfigureRouteTest.php @@ -18,7 +18,7 @@ class ModuleConfigureRouteTest extends KernelTestBase { /** * {@inheritdoc} */ - protected static $modules = ['system', 'user', 'path_alias', 'file']; + protected static $modules = ['system', 'user', 'path_alias']; /** * @var \Drupal\Core\Routing\RouteProviderInterface