Skip to content

Commit 1fca087

Browse files
committed
[no ci] wip: docs: revamp the customizing the admin doc
1 parent db1cb96 commit 1fca087

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

admin/customizing.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,56 @@
1-
# Customizing the Admin
1+
# Customizing the Guessers
2+
3+
Using `<HydraAdmin>` or `<OpenApiAdmin>` directly is a great way to quickly get started with API Platform Admin. They will introspect your API's schema and automatically generate CRUD pages for all the resources it exposes. They will even [configure filtering, sorting, and real-time updates with Mercure](./schema-org.md) if your API supports it.
4+
5+
For some this may be enough, but you will often find yourself wanting to customize the generated pages further. For instance, you may want to:
6+
7+
- Hide or reorder resources in the menu
8+
- Hide or reorder columns in the list view
9+
- Hide or reorder fields in the show view
10+
- Hide or reorder inputs in the create and edit forms
11+
- Customize the generated list, e.g. add a default sort order
12+
- Customize the generated inputs, e.g. set a custom label or make a text input multiline
13+
14+
Such changes can't be achieved by modifying the Schema, they require customizing the React components generated by API Platform Admin.
15+
16+
Fortunately, API Platform Admin has you covered!
17+
18+
## From `<AdminGuesser>` To `<ResourceGuesser>`
19+
20+
If you are using `<HydraAdmin>` or `<OpenApiAdmin>` directly, there is a simple way to start customizing the generated pages.
21+
22+
Simply open your browser's developer tools and look at the console. You will see messages like this:
23+
24+
```
25+
If you want to override at least one resource, paste this content in the <AdminGuesser> component of your app:
26+
27+
<ResourceGuesser name="books" />
28+
<ResourceGuesser name="greetings" />
29+
<ResourceGuesser name="reviews" />
30+
```
31+
32+
This message tells you which resources are exposed by your API and how to customize the generated pages for each of them.
33+
34+
Let's say we'd like to hide the `greetings` resource from the menu. We can do this by replacing the `<AdminGuesser>` component (`<HydraAdmin>` in our case) children with a list of `<ResourceGuesser>`:
35+
36+
```diff
37+
-import { HydraAdmin } from "@api-platform/admin";
38+
+import { HydraAdmin, ResourceGuesser } from "@api-platform/admin";
39+
40+
const App = () => (
41+
- <HydraAdmin entrypoint={...} />
42+
+ <HydraAdmin entrypoint={...}>
43+
+ <ResourceGuesser name="books" />
44+
+ <ResourceGuesser name="reviews" />
45+
+ </HydraAdmin>
46+
);
47+
```
48+
49+
Now the `greetings` resource will no longer be displayed in the menu.
50+
51+
![Customized Admin menu](./images/admin-menu.png)
52+
53+
## ...
254

355
Customizing API Platform Admin is easy and idiomatic. The tool gives you the ability to customize everything, from the list of resource types that must be administrable to every single input or button.
456

admin/images/admin-menu.png

97.4 KB
Loading

0 commit comments

Comments
 (0)