I need to write a new api endoint, very similar to the api/search/order
endpoint using a custom implementation. Basically i want to add a new response format for another system.
This will also be a new route like api/custom/search/order
.
My approach is that i want to write a new controller by extending the existing controller, defined as follows:
+--------------+---------------------------------------------------------------------------------------+
| Property | Value |
+--------------+---------------------------------------------------------------------------------------+
| Route Name | api.order.search |
| Path | /api/search/order{path} |
| Path Regex | {^/api/search/order(?P<path>(?:\/[0-9a-f]{32}\/(?:extensions\/)?[a-zA-Z-]+)*\/?)$}sDu |
| Host | ANY |
| Host Regex | |
| Scheme | ANY |
| Method | POST |
| Requirements | path: (\/[0-9a-f]{32}\/(extensions\/)?[a-zA-Z-]+)*\/? |
| | version: \d+ |
| Class | Symfony\Component\Routing\Route |
| Defaults | _controller: Shopware\Core\Framework\Api\Controller\ApiController::search() |
| | _routeScope: array (0 => 'api',) |
| | entityName: order |
| Options | compiler_class: Symfony\Component\Routing\RouteCompiler |
| | utf8: true |
+--------------+---------------------------------------------------------------------------------------+
From my current setup i was able to write a new controller but the controller can not be found in the routes as there is no annotation
in the original one. I could add a custom annotation but i was looking at the original definition and actually there is no annotation.
public function search(Request $request, Context $context, ResponseFactoryInterface $responseFactory, string $entityName, string $path): Response
{
[$criteria, $repository] = $this->resolveSearch($request, $context, $entityName, $path);
$result = $context->scope(Context::CRUD_API_SCOPE, function (Context $context) use ($repository, $criteria): EntitySearchResult {
return $repository->search($criteria, $context);
});
$definition = $this->getDefinitionOfPath($entityName, $path, $context);
return $responseFactory->createListingResponse($criteria, $result, $definition, $request, $context);
}
My question is: Is there something like a dynamic annotation which will automatically be created? I can not find any information about how the path for /api/search/order{path}
is defined.
/**
* @Route(defaults={"_routeScope"={"api"}})
*/
class OrderActionController extends ApiController
{
public function search(Request $request, Context $context, ResponseFactoryInterface $responseFactory, string $entityName, string $path): Response
{
}
}
I did figure it out. The annotations for the
api.search.order
are defined in the classShopware\Core\System\CustomEntity\Api\CustomEntityApiController
.Shopware uses a dynamic annotation which will be used to create the routes. I was looking for a specific annotation and therefore was not able to find it.