Skip to content

Commit

Permalink
DOC Document new FormSchemaController
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Nov 14, 2024
1 parent ede5aa4 commit 8154fb2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
6 changes: 3 additions & 3 deletions en/02_Developer_Guides/02_Controllers/07_CMS_JSON_APIs.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ summary: Creating standardised JSON APIs for authenticated users in the CMS.

This document contains a standard set of conventions to be used when creating JSON APIs in the CMS that are used in conjunction with AJAX requests from authenticated CMS users.

To view an example of a controller that follows these standards see [`LinkFieldController`](https://github.com/silverstripe/silverstripe-linkfield/blob/4/src/Controllers/LinkFieldController.php).
To view an example of a controller that follows these standards see [`LinkFieldController`](api:SilverStripe\LinkField\Controllers\LinkFieldController).

## Making the controller "REST-like" and its relation with `FormSchema`

Expand All @@ -34,14 +34,14 @@ Use the [`required_permission_codes`](api:SilverStripe\Admin\AdminController->re

See [user permissions](/developer_guides/security/permissions/) for more information about declaring permissions.

If you need form schema functionality, you will need to create a subclass of [`LeftAndMain`](api:SilverStripe\Admin\LeftAndMain) instead. All of the above still applies, but by default a menu item will be created for your new controller. To remove it from the CMS menu, set the [`ignore_menuitem`](api:SilverStripe\Admin\LeftAndMain->ignore_menuitem) configuration property to true for your class, i.e `private static $ignore_menuitem = true;`.
If you need form schema functionality, you will need to create a subclass of [`FormSchemaController`](api:SilverStripe\Admin\FormSchemaController) instead.

## Handling requests with `$url_handlers`

Utilise the [`url_handlers`](api:SilverStripe\Control\Controller->url_handlers) configuration property to get the following benefits:

- Ensure the HTTP request method aligns with the intended use for each method, for instance, restricting it to GET or POST.
- If subclassing `LeftAndMain`, avoid potential conflicts with existing methods on the superclass, such as [`LeftAndMain::sort()`](api:SilverStripe\Admin\LeftAndMain::sort()), by structuring the endpoint URL segment as `sort` and associating it with a method like `MySomethingController::apiSort()`.
- If you're using form schema logic in a subclass of `LeftAndMain`, avoid potential conflicts with existing methods on the superclass, such as [`LeftAndMain::sort()`](api:SilverStripe\Admin\LeftAndMain::sort()), by structuring the endpoint URL segment as `sort` and associating it with a method like `MySomethingController::apiSort()`.

Use the request param `$ItemID` if you need a record ID into a URL so that you have an endpoint for a specific record. Use `$ItemID` because it's consistent with the request param used in Form Schema requests. For example, to use `$ItemID` in a GET request to view a single record:

Expand Down
22 changes: 17 additions & 5 deletions en/08_Changelogs/6.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -606,14 +606,25 @@ See the [full list of removed and changed API](#api-removed-and-changed) to see

### Changes to `LeftAndMain` and its subclasses {#leftandmain-refactor}

[`LeftAndMain`](api:SilverStripe\Admin\LeftAndMain) has historically been the superclass for all controllers routed in `/admin/*` (i.e. all controllers used in the CMS). That class includes a lot of boilerplate functionality for setting up a menu, edit form, etc which a lot of controllers don't need.
[`LeftAndMain`](api:SilverStripe\Admin\LeftAndMain) has historically been the superclass for all controllers routed in `/admin/*` (i.e. all controllers used in the CMS). It's also the superclass for admin-routed controllers which manage modal forms. That class includes a lot of boilerplate functionality for setting up a menu, edit form, etc which a lot of controllers don't need.

A new [`AdminController`](api:SilverStripe\Admin\AdminController) has been created which provides the `/admin/*` routing functionality and permission checks that `LeftAndMain` used to be responsible for. If you have a controller which needs to be routed through `/admin/*` with the relevant CMS permission checks, but which does *not* need a menu item on the left or an edit form, you should update that class to be a subclass of `AdminController` instead.

As a result of this change, to following classes are now direct subclasses of `AdminController`:
The new [`FormSchemaController`](api:SilverStripe\Admin\FormSchemaController) class (which is a subclass of `AdminController`) now owns the logic required for injecting and managing forms inside modals.

- [`SudoModeController`](api:SilverStripe\Admin\SudoModeController) - used to be a subclass of `LeftAndMain`.
- [`CMSExternalLinksController`](api:SilverStripe\ExternalLinks\Controllers\CMSExternalLinksController) - used to be a direct subclass of [`Controller`](api:SilverStripe\Control\Controller).
As a result of these changes, the following classes have had their class hierarchy updated:

|class|old superclass|new superclass|
|---|---|---|
|[`LeftAndMain`](api:SilverStripe\Admin\LeftAndMain)|[`Controller`](api:SilverStripe\Control\Controller)|`FormSchemaController`|
|[`SudoModeController`](api:SilverStripe\Admin\SudoModeController)|`LeftAndMain`|`AdminController`|
|[`ElementalAreaController`](api:DNADesign\Elemental\Controllers\ElementalAreaController)|[`CMSMain`](api:SilverStripe\CMS\Controllers\CMSMain)|`FormSchemaController`|
|[`HistoryViewerController`](api:SilverStripe\VersionedAdmin\Controllers\HistoryViewerController)|`LeftAndMain`|`FormSchemaController`|
|[`UserDefinedFormAdmin`](api:SilverStripe\UserForms\Control\UserDefinedFormAdmin)|`LeftAndMain`|`FormSchemaController`|
|[`AdminRegistrationController`](api:SilverStripe\MFA\Controller\AdminRegistrationController)|`LeftAndMain`|`AdminController`|
|[`LinkFieldController`](api:SilverStripe\LinkField\Controllers\LinkFieldController)|`LeftAndMain`|`FormSchemaController`|
|[`SubsiteXHRController`](api:SilverStripe\Subsites\Controller\SubsiteXHRController)|`LeftAndMain`|`AdminController`|
|[`CMSExternalLinksController`](api:SilverStripe\ExternalLinks\Controllers\CMSExternalLinksController)|`Controller`|`AdminController`|

The `tree_class` configuration property on `LeftAndMain` and its subclasses has be renamed to [`model_class`](api:SilverStripe\Admin\LeftAndMain->model_class). This is used in methods like [`getRecord()`](api:SilverStripe\Admin\LeftAndMain::getRecord()) to get a record of the correct class.

Expand Down Expand Up @@ -780,7 +791,8 @@ Note that the change from `ViewableData` to `ModelData` specifically was made to

### GraphQL removed from the CMS {#graphql-removed}

> [!INFO] If you need to use GraphQL in your project for public-facing frontend schemas, you can still install and use the [`silverstripe/graphql`](https://github.com/silverstripe/silverstripe-graphql) module.
> [!NOTE]
> If you need to use GraphQL in your project for public-facing frontend schemas, you can still install and use the [`silverstripe/graphql`](https://github.com/silverstripe/silverstripe-graphql) module.

GraphQL has been removed from the admin section of the CMS and is no longer installed when creating a new project using [`silverstripe/installer`](https://github.com/silverstripe/silverstripe-installer), or an existing project that uses [`silverstripe/recipe-cms`](https://github.com/silverstripe/recipe-cms). All existing functionality in the CMS that previously relied on GraphQL has been migrated to use regular Silverstripe CMS controllers instead.

Expand Down

0 comments on commit 8154fb2

Please sign in to comment.