person: add api endpoint for altname + implement getValidationGroups

This commit is contained in:
nobohan 2021-11-26 12:48:55 +01:00
parent 438cb7317a
commit 3d3ce7814b

View File

@ -78,4 +78,35 @@ class PersonApiController extends ApiController
new Role(PersonVoter::CREATE));
$person->setCenter($centers[0]); */
}
/**
* @Route("/api/1.0/person/config/alt_names.{_format}",
* name="chill_person_config_alt_names",
* requirements={
* "_format": "json"
* }
* )
*/
public function configAltNames(Request $request, string $_format): Response
{
//TODO get alt_name config from chill person
$configAltNames = ["key" => "jeune_fille", "labels" => ["fr" => "Nom de naisssance" ]]; //TODO fake data
return $this->json($configAltNames, Response::HTTP_OK, [], ['groups' => ['read']]);
}
public function getValidationGroups(string $action, Request $request, string $_format, $entity): ?array
{
if ($action === '_entity'){
if ($request->getMethod() === Request::METHOD_POST){
return ["creation"];
}
if (($request->getMethod() === Request::METHOD_PATCH) || ($request->getMethod() === Request::METHOD_PUT)){
return ["general"];
}
};
return parent::getValidationGroups($action, $request, $_format, $entity);
}
}