With GET methodology we will do one thing like this
instance.consumer path: 'instance/{consumer}' defaults: _controller: 'DrupalexampleControllerExampleController::content material' necessities: _permission: 'entry content material' consumer: ^[a-zA-Z0-9_]+
so it units consumer param as required and likewise limits its format.
However I would love to do one thing comparable with POST methodology. Tried this, however not working:
instance.consumer path: 'instance' strategies: [POST] defaults: _controller: 'DrupalexampleControllerExampleController::content material' necessities: _permission: 'entry content material' consumer: ^[a-zA-Z0-9_]+
EDIT:
Positive I can set some logic inside controller like this, however it would not really feel proper:
public operate retailer(Request $request) { $params = json_decode($request->getContent(), TRUE); //I am making an attempt to keep away from utilizing these situations inside controller strategies if(empty($params['user'])){ //return error response }else{ if (!preg_match('/^[a-zA-Z0-9_]+/', $params['user'])) { //return error response } } //return success response }
So what’s drupal method to do it?