Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 292250

Use some arcane magic to automatically discover typed data definitions for route parameters

$
0
0

Spin-off from #1943846: Improve ParamConverterManager and developer experience for ParamConverters to keep that issue solely focused on the ParamConverter and basic upcasting.

Quick summary, copy&pasted from the other issue:

This patch introduces a new layer to our upcasting strategy. In order to increase the DX when composing new route definitions we can potentially use some magic to automatically discover the typed data types for the parameters of a route instead of having to manually define them one-by-one.

Here is how the entire concept would look (the new layer being the typed data resolvers):

TypedDataResolverManager (automatically deriving typed data types)

Invoked by a RoutingEvents::ALTER subscriber (TypedDataSubscriber). Iterates over every registered typed data resolver service (TypedDataResolverInterface) to try and generate typed data definitions based on whatever strategy that resolver service implements. So far we got two resolver strategies: a) EntityResolver (_entity_form/_entity_list) and b) Reflection (match the type hint of a controller argument to a typed data type).

ParamConverterManager (registering converters)

Invoked by a RoutingEvents::ALTER subscriber (ParamConverterSubscriber) with lower priority than that of TypedDataSubscriber so it runs after we run through the different typed data type resolver strategies. Iterates over every parameter defined in $route->getOption('parameters') (basically, the array structures our typed data resolvers previously filled with stuff and all the parameters that were defined manually). And tries to find a converter service for each of them. There is a maximum of one converter service for each parameter as multiple layers of parameter converters for the same parameter don't make much sense imho. If it finds one that applies, it writes the it's id in the route options ($parameter['converter'] = $id_of_service_that_applies) and continues with the next parameter (if any).

RouteEnhancer (actual upcasting)

The ParamConverterManager is also a RouteEnhancer (as it was before too). It then iterates over all defined parameters and invokes the previously set converter to try and upcast the given argument.

I am filing as feature request although that makes me feel kinda uneasy as I hope we can still get this in for D8 as it was part of the original proposal.


Viewing all articles
Browse latest Browse all 292250

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>