-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Standardise how we create API/FormSchema endpoint in the CMS #1589
Comments
I've created one card for now. But this will probably need to be split in a few cards to make sense. Maybe one of the way we do this is fine and we just need to agree and document it. I'd be keen to explore what helper classes we can put in place to simplify the process beyond that. (Creating a |
I think I'd be more in favour of a private const DEFAULT_JSON_OPTIONS = JSON_UNESCAPED_SLASHES + JSON_UNESCAPED_UNICODE;
protected function jsonResponse(array $data, $jsonOptions = self::DEFAULT_JSON_OPTIONS): HTTPResponse
{
$response = $this->getResponse();
$body = $json_encode($data, $jsonOptions);
// if json error, do something to handle it
$response
->addHeader('Content-type', 'application/json')
->setBody($body);
$this->invokeWithExtensions('updateJsonResponse', $response);
return $response;
} |
Seems like there's a few patterns here 1. extends LeftAndMain + $url_segment (seems good)
2. extends LeftAndMain + $url_handler (seems good)
3. extends Controller + LeftAndMainExtension + action that returns a MyController
4. extends Controller, routes.yml and Member check (hopefully)
5. Other
|
Ultimately I'd like to see a controller higher up the class hierarchy than |
Yeah the logical thing is probably |
That's also the approach Symfony has taken. |
As mentioned in meeting, JSONReponse wouldn't work great with when you go $this->getResponse() in a controller as getResponse() returns an HTTPResponse, so using instantiating a new JSONReponse would require copying over everything from the HTTPReponse to the JSONResponse |
Just notice that campaign Admin seems to have form schema validation working and is using POST to submit data back. That might be the closest example we have to what Form Schema was meant to do. campaign-2023-10-28_20.51.07.webm |
I'm really starting to wonder if the idea of "standardise/centralise" is something that's even viable or desirable. It seems that a long time ago Silverstripe adopted a philosophy of "passing control" from one object to another to handle requests - for instance read the class docblock for RequestHandler - https://github.com/silverstripe/silverstripe-framework/blob/5/src/Control/RequestHandler.php#L19 The original philosophy seems it was built around the idea of having a series of nested RequestHandlers that handle their own little bit of the URL, rather than more centralised routing method For instance Controller and FormField both extend RequestHandler and Form implements HasRequestHandler - i.e. everything handles requests. The routing for the above will (as I understand it, the exact details don't matter)
My point here is that Silverstripe CMS has for a long time had a very non centralised routing system and instead uses a nested routing system. This is unfortunately a confusing system that, while I'm sure the conventions made intuitive sense to the original designers of this, years later it now basically requires the use of a debugger to work out how something got routed. The nested routing does not lend itself well to any attempts at centralisation. Any dreams of a single page that shows all of the routes seems very far away. While we could probably do something to centralise things e.g. make it so that you can send treedropdown XHR requests to |
Some documentation has been written, but I'm not confident it meets the ACs of this cards. I'm moving this card to the CMS 5.3 milestone. |
Story
As a CMS developer, I want a clear and standardised way to add endpoints in the CMS.
Context
We just seem to be peppering new API endpoints throughout the CMS whenever we need them without thinking things through. This is creating technical debt.
ShareDraftContentControllerExtension
creates aMakeShareDraftLink
action but because it's added on theController
class the action is added on every single controllerUserDefinedFormAdmin
extends LeftAndMainHistoryViewerController
extends left and main so we can create a few form schema endpoints.Acceptance criteria
Related cards
The text was updated successfully, but these errors were encountered: