jsonapi.services.yml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. parameters:
  2. jsonapi.base_path: /jsonapi
  3. services:
  4. jsonapi.serializer:
  5. class: Drupal\jsonapi\Serializer\Serializer
  6. calls:
  7. - [setFallbackNormalizer, ['@serializer']]
  8. arguments: [{ }, { }]
  9. serializer.normalizer.http_exception.jsonapi:
  10. class: Drupal\jsonapi\Normalizer\HttpExceptionNormalizer
  11. arguments: ['@current_user']
  12. tags:
  13. - { name: jsonapi_normalizer }
  14. serializer.normalizer.unprocessable_entity_exception.jsonapi:
  15. class: Drupal\jsonapi\Normalizer\UnprocessableHttpEntityExceptionNormalizer
  16. arguments: ['@current_user']
  17. tags:
  18. # This must have a higher priority than the 'serializer.normalizer.http_exception.jsonapi' to take effect.
  19. - { name: jsonapi_normalizer, priority: 1 }
  20. serializer.normalizer.entity_access_exception.jsonapi:
  21. class: Drupal\jsonapi\Normalizer\EntityAccessDeniedHttpExceptionNormalizer
  22. arguments: ['@current_user']
  23. tags:
  24. # This must have a higher priority than the 'serializer.normalizer.http_exception.jsonapi' to take effect.
  25. - { name: jsonapi_normalizer, priority: 1 }
  26. serializer.normalizer.field_item.jsonapi:
  27. class: Drupal\jsonapi\Normalizer\FieldItemNormalizer
  28. arguments: ['@entity_type.manager']
  29. tags:
  30. - { name: jsonapi_normalizer }
  31. serializer.normalizer.field.jsonapi:
  32. class: Drupal\jsonapi\Normalizer\FieldNormalizer
  33. tags:
  34. - { name: jsonapi_normalizer }
  35. serializer.normalizer.resource_identifier.jsonapi:
  36. class: Drupal\jsonapi\Normalizer\ResourceIdentifierNormalizer
  37. arguments: ['@entity_field.manager']
  38. tags:
  39. - { name: jsonapi_normalizer }
  40. serializer.normalizer.data.jsonapi:
  41. class: Drupal\jsonapi\Normalizer\DataNormalizer
  42. tags:
  43. - { name: jsonapi_normalizer }
  44. serializer.normalizer.resource_object.jsonapi:
  45. class: Drupal\jsonapi\Normalizer\ResourceObjectNormalizer
  46. arguments: ['@jsonapi.normalization_cacher']
  47. tags:
  48. - { name: jsonapi_normalizer }
  49. jsonapi.normalization_cacher:
  50. class: Drupal\jsonapi\EventSubscriber\ResourceObjectNormalizationCacher
  51. calls:
  52. - ['setRenderCache', ['@render_cache']]
  53. tags:
  54. - { name: event_subscriber }
  55. serializer.normalizer.content_entity.jsonapi:
  56. class: Drupal\jsonapi\Normalizer\ContentEntityDenormalizer
  57. arguments: ['@entity_type.manager', '@entity_field.manager', '@plugin.manager.field.field_type']
  58. tags:
  59. - { name: jsonapi_normalizer }
  60. serializer.normalizer.config_entity.jsonapi:
  61. class: Drupal\jsonapi\Normalizer\ConfigEntityDenormalizer
  62. arguments: ['@entity_type.manager', '@entity_field.manager', '@plugin.manager.field.field_type']
  63. tags:
  64. - { name: jsonapi_normalizer }
  65. serializer.normalizer.jsonapi_document_toplevel.jsonapi:
  66. class: Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer
  67. arguments: ['@entity_type.manager', '@jsonapi.resource_type.repository']
  68. tags:
  69. - { name: jsonapi_normalizer }
  70. serializer.normalizer.link_collection.jsonapi:
  71. class: Drupal\jsonapi\Normalizer\LinkCollectionNormalizer
  72. tags:
  73. - { name: jsonapi_normalizer }
  74. serializer.normalizer.relationship.jsonapi:
  75. class: Drupal\jsonapi\Normalizer\RelationshipNormalizer
  76. tags:
  77. - { name: jsonapi_normalizer }
  78. serializer.encoder.jsonapi:
  79. class: Drupal\jsonapi\Encoder\JsonEncoder
  80. tags:
  81. - { name: jsonapi_encoder, format: 'api_json' }
  82. jsonapi.resource_type.repository:
  83. class: Drupal\jsonapi\ResourceType\ResourceTypeRepository
  84. arguments: ['@entity_type.manager', '@entity_type.bundle.info', '@entity_field.manager', '@cache.jsonapi_resource_types', '@event_dispatcher']
  85. jsonapi.route_enhancer:
  86. class: Drupal\jsonapi\Routing\RouteEnhancer
  87. tags:
  88. - { name: route_enhancer }
  89. jsonapi.field_resolver:
  90. class: Drupal\jsonapi\Context\FieldResolver
  91. arguments: ['@entity_type.manager', '@entity_field.manager', '@entity_type.bundle.info', '@jsonapi.resource_type.repository', '@module_handler']
  92. jsonapi.include_resolver:
  93. class: Drupal\jsonapi\IncludeResolver
  94. arguments:
  95. - '@entity_type.manager'
  96. - '@jsonapi.entity_access_checker'
  97. paramconverter.jsonapi.entity_uuid:
  98. parent: paramconverter.entity
  99. class: Drupal\jsonapi\ParamConverter\EntityUuidConverter
  100. calls:
  101. - [setLanguageManager, ['@language_manager']]
  102. tags:
  103. # Priority 10, to ensure it runs before @paramconverter.entity.
  104. - { name: paramconverter, priority: 10 }
  105. paramconverter.jsonapi.resource_type:
  106. class: Drupal\jsonapi\ParamConverter\ResourceTypeConverter
  107. arguments: ['@jsonapi.resource_type.repository']
  108. tags:
  109. - { name: paramconverter }
  110. jsonapi.exception_subscriber:
  111. class: Drupal\jsonapi\EventSubscriber\DefaultExceptionSubscriber
  112. tags:
  113. - { name: event_subscriber }
  114. arguments: ['@jsonapi.serializer', '%serializer.formats%']
  115. logger.channel.jsonapi:
  116. parent: logger.channel_base
  117. arguments: ['jsonapi']
  118. # Cache.
  119. cache.jsonapi_memory:
  120. class: Drupal\Core\Cache\MemoryCache\MemoryCache
  121. public: false
  122. # A chained cache with an in-memory cache as the first layer and a database-
  123. # backed cache as the fallback is used. The first layer (memory) is necessary
  124. # because ResourceType value objects are retrieved many times during a
  125. # request. The second layer (by default a database) is necessary to avoid
  126. # recomputing the ResourceType value objects on every request.
  127. cache.jsonapi_resource_types:
  128. class: Drupal\Core\Cache\BackendChain
  129. calls:
  130. - [appendBackend, ['@cache.jsonapi_memory']]
  131. - [appendBackend, ['@cache.default']]
  132. tags: [{ name: cache.bin }]
  133. cache.jsonapi_normalizations:
  134. class: Drupal\Core\Cache\CacheBackendInterface
  135. tags:
  136. - { name: cache.bin }
  137. factory: cache_factory:get
  138. arguments: [jsonapi_normalizations]
  139. # Route filter.
  140. jsonapi.route_filter.format_setter:
  141. class: Drupal\jsonapi\Routing\EarlyFormatSetter
  142. tags:
  143. # Set to a high priority so it runs before content_type_header_matcher
  144. # and other filters that might throw exceptions.
  145. - { name: route_filter, priority: 100 }
  146. # Access Control
  147. jsonapi.entity_access_checker:
  148. class: Drupal\jsonapi\Access\EntityAccessChecker
  149. public: false
  150. arguments: ['@jsonapi.resource_type.repository', '@router.no_access_checks', '@current_user', '@entity.repository']
  151. calls:
  152. - [setNodeRevisionAccessCheck, ['@?access_check.node.revision']] # This is only injected when the service is available.
  153. - [setMediaRevisionAccessCheck, ['@?access_check.media.revision']] # This is only injected when the service is available.
  154. # This is a temporary measure. JSON:API should not need to be aware of the Content Moderation module.
  155. - [setLatestRevisionCheck, ['@?access_check.latest_revision']] # This is only injected when the service is available.
  156. access_check.jsonapi.relationship_field_access:
  157. class: Drupal\jsonapi\Access\RelationshipFieldAccess
  158. arguments: ['@jsonapi.entity_access_checker']
  159. tags:
  160. - { name: access_check, applies_to: _jsonapi_relationship_field_access, needs_incoming_request: TRUE }
  161. # Route filters.
  162. method_filter.jsonapi:
  163. public: false
  164. class: Drupal\jsonapi\Routing\ReadOnlyModeMethodFilter
  165. decorates: method_filter
  166. arguments: ['@method_filter.jsonapi.inner', '@config.factory']
  167. # Controller.
  168. jsonapi.entity_resource:
  169. class: Drupal\jsonapi\Controller\EntityResource
  170. arguments:
  171. - '@entity_type.manager'
  172. - '@entity_field.manager'
  173. - '@jsonapi.resource_type.repository'
  174. - '@renderer'
  175. - '@entity.repository'
  176. - '@jsonapi.include_resolver'
  177. - '@jsonapi.entity_access_checker'
  178. - '@jsonapi.field_resolver'
  179. - '@jsonapi.serializer'
  180. - '@datetime.time'
  181. - '@current_user'
  182. jsonapi.file_upload:
  183. class: Drupal\jsonapi\Controller\FileUpload
  184. arguments:
  185. - '@current_user'
  186. - '@entity_field.manager'
  187. - '@jsonapi.file.uploader.field'
  188. - '@http_kernel'
  189. # Event subscribers.
  190. jsonapi.custom_query_parameter_names_validator.subscriber:
  191. class: Drupal\jsonapi\EventSubscriber\JsonApiRequestValidator
  192. tags:
  193. - { name: event_subscriber }
  194. jsonapi.resource_response.subscriber:
  195. class: Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber
  196. arguments: ['@jsonapi.serializer']
  197. tags:
  198. - { name: event_subscriber }
  199. jsonapi.resource_response_validator.subscriber:
  200. class: Drupal\jsonapi\EventSubscriber\ResourceResponseValidator
  201. arguments: ['@logger.channel.jsonapi', '@module_handler', '@app.root']
  202. calls:
  203. - [setValidator, []]
  204. tags:
  205. - { name: event_subscriber, priority: 1000 }
  206. # Revision management.
  207. jsonapi.version_negotiator:
  208. class: Drupal\jsonapi\Revisions\VersionNegotiator
  209. public: false
  210. tags:
  211. - { name: service_collector, tag: jsonapi_version_negotiator, call: addVersionNegotiator }
  212. jsonapi.version_negotiator.default:
  213. arguments: ['@entity_type.manager']
  214. public: false
  215. abstract: true
  216. jsonapi.version_negotiator.id:
  217. class: Drupal\jsonapi\Revisions\VersionById
  218. parent: jsonapi.version_negotiator.default
  219. tags:
  220. - { name: jsonapi_version_negotiator, negotiator_name: 'id' }
  221. jsonapi.version_negotiator.rel:
  222. class: Drupal\jsonapi\Revisions\VersionByRel
  223. parent: jsonapi.version_negotiator.default
  224. tags:
  225. - { name: jsonapi_version_negotiator, negotiator_name: 'rel' }
  226. jsonapi.resource_version.route_enhancer:
  227. class: Drupal\jsonapi\Revisions\ResourceVersionRouteEnhancer
  228. public: false
  229. arguments:
  230. - '@jsonapi.version_negotiator'
  231. tags:
  232. - { name: route_enhancer }
  233. # Deprecated services.
  234. serializer.normalizer.htt_exception.jsonapi:
  235. alias: serializer.normalizer.http_exception.jsonapi
  236. deprecated: The "%service_id%" service is deprecated. You should use the 'serializer.normalizer.http_exception.jsonapi' service instead.
  237. # @todo Remove once https://www.drupal.org/project/drupal/issues/2940383 lands.
  238. jsonapi.file.uploader.field:
  239. class: Drupal\jsonapi\Controller\TemporaryJsonapiFileFieldUploader
  240. public: false
  241. arguments: ['@logger.channel.file', '@file_system', '@file.mime_type.guesser', '@token', '@lock', '@config.factory']