11# Customizing the Schema
22
33Both [ ` HydraAdmin ` ] ( ./components.md#hydraadmin ) and [ ` OpenApiAdmin ` ] ( ./components.md#openapiadmin )
4- leverage introspection of the API schema to discover its capabilities, like ** filtering** and
4+ use introspection of the API schema to discover its capabilities, like ** filtering** and
55** sorting** .
66
7- They also detect wether the API has real-time capabilities using [ Mercure ] ( ./real-time-mercure.md ) ,
8- and automatically enable it if it does .
7+ They also detect whether the API has real-time capabilities through
8+ [ Mercure ] ( ./real-time-mercure.md ) . When it does, Admin enables real-time updates automatically .
99
10- Lastly, API Platform Admin has native support for the popular
11- [ Schema.org ] ( ./schema.md#about-schemaorg ) vocabulary, which enables it to automatically use the
12- field type matching your data, or display a related resource's name instead of its IRI.
10+ API Platform Admin also has native support for the popular [ Schema.org ] ( ./schema.md#about-schemaorg )
11+ vocabulary. This support lets it automatically use the field type matching your data, or display a
12+ related resource's name instead of its IRI.
1313
1414## Adding Filtering Capabilities
1515
16- You can add the [ ` ApiFilter ` attribute] ( ../core/filters.md#apifilter-attribute ) to an API Platform
17- resource to configure a filter on a property.
16+ You can use the [ ` QueryParameter ` attribute] ( ../core/filters.md#declaring-parameters ) on an API
17+ Platform resource to configure a filter on a property.
1818
1919For instance, here is how configure filtering on the ` id ` , ` title ` and ` author ` properties of a
2020` Book ` resource:
@@ -24,18 +24,20 @@ For instance, here is how configure filtering on the `id`, `title` and `author`
2424// api/src/Entity/Book.php
2525namespace App\Entity;
2626
27- use ApiPlatform\Metadata\ApiFilter;
27+ use ApiPlatform\Doctrine\Orm\Filter\ExactFilter;
28+ use ApiPlatform\Doctrine\Orm\Filter\PartialSearchFilter;
2829use ApiPlatform\Metadata\ApiResource;
29- use ApiPlatform\Doctrine\Orm\Filter\SearchFilter ;
30+ use ApiPlatform\Metadata\QueryParameter ;
3031use Doctrine\ORM\Mapping as ORM;
3132
32- #[ApiResource]
33+ #[ApiResource(
34+ parameters: [
35+ 'id' => new QueryParameter(filter: new ExactFilter()),
36+ 'title' => new QueryParameter(filter: new PartialSearchFilter()),
37+ 'author' => new QueryParameter(filter: new PartialSearchFilter()),
38+ ]
39+ )]
3340#[ORM\Entity]
34- #[ApiFilter(SearchFilter::class, properties: [
35- 'id' => 'exact',
36- 'title' => 'ipartial',
37- 'author' => 'ipartial'
38- ])]
3941class Book
4042{
4143 // ...
@@ -47,12 +49,12 @@ filter on the selected properties.
4749
4850![ Filtering on the title property] ( ./images/admin-filter.png )
4951
50- ** Tip:** Learn more about the [ ` ApiFilter ` attribute ] ( ../core/filters.md#apifilter-attribute ) in the
51- core documentation.
52+ ** Tip:** Learn more about the [ available filters ] ( ../core/filters.md#list-of-available-filters ) in
53+ the core documentation.
5254
5355## Adding Sorting Capabilities
5456
55- You can also use the [ ` ApiFilter ` attribute] ( ../core/filters.md#apifilter-attribute ) on an API
57+ You can also use the [ ` QueryParameter ` attribute] ( ../core/filters.md#declaring-parameters ) on an API
5658Plaform resource to configure sorting.
5759
5860For instance, here is how to configure sorting on the ` id ` , ` isbn ` , ` title ` , ` author ` and
@@ -63,20 +65,24 @@ For instance, here is how to configure sorting on the `id`, `isbn`, `title`, `au
6365// api/src/Entity/Book.php
6466namespace App\Entity;
6567
66- use ApiPlatform\Metadata\ApiFilter ;
68+ use ApiPlatform\Doctrine\Orm\Filter\SortFilter ;
6769use ApiPlatform\Metadata\ApiResource;
68- use ApiPlatform\Doctrine\Orm\Filter\SearchFilter ;
70+ use ApiPlatform\Metadata\QueryParameter ;
6971use Doctrine\ORM\Mapping as ORM;
7072
71- #[ApiResource]
73+ #[ApiResource(
74+ parameters: [
75+ 'order' => new QueryParameter(filter: new SortFilter(), property: 'id'),
76+ 'orderIsbn' => new QueryParameter(filter: new SortFilter(), property: 'isbn'),
77+ 'orderTitle' => new QueryParameter(filter: new SortFilter(), property: 'title'),
78+ 'orderAuthor' => new QueryParameter(filter: new SortFilter(), property: 'author'),
79+ 'orderPublicationDate' => new QueryParameter(
80+ filter: new SortFilter(),
81+ property: 'publicationDate'
82+ ),
83+ ]
84+ )]
7285#[ORM\Entity]
73- #[ApiFilter(OrderFilter::class, properties: [
74- 'id' => 'ASC',
75- 'isbn' => 'ASC',
76- 'title' => 'ASC',
77- 'author' => 'ASC',
78- 'publicationDate' => 'DESC'
79- ])]
8086class Book
8187{
8288 // ...
@@ -88,7 +94,7 @@ selected columns sortable.
8894
8995![ Sorting by the title property] ( ./images/admin-sort.png )
9096
91- ** Tip:** Learn more about the [ ` ApiFilter ` attribute ] ( ../core/filters.md#apifilter-attribute ) in the
97+ ** Tip:** Learn more about the [ ` SortFilter ` ] ( ../core/filters.md#list-of-available-filters ) in the
9298core documentation.
9399
94100## Enabling Real-Time Updates
@@ -122,19 +128,19 @@ API Platform Admin has native support for the popular [Schema.org](https://schem
122128> Schema.org is a collaborative, community activity with a mission to create, maintain, and promote
123129> schemas for structured data on the Internet, on web pages, in email messages, and beyond.
124130
125- To leverage this capability, your API must use the JSON-LD format and the appropriate Schema.org
126- types. The following examples will use [ API Platform Core] ( ../core/ ) to create such API, but keep in
127- mind that this feature will work with any JSON-LD API using the Schema.org vocabulary, regardless of
128- the used web framework or programming language.
131+ To use this capability, your API must use the JSON-LD format and the appropriate Schema.org types.
132+ The following examples use [ API Platform Core] ( ../core/ ) to create such an API. This feature works
133+ with any JSON-LD API that uses the Schema.org vocabulary, regardless of the web framework or
134+ programming language.
129135
130136## Displaying Related Resource's Name Instead of its IRI
131137
132138By default, IRIs of related objects are displayed in lists and forms. However, it is often more
133139user-friendly to display a string representation of the resource (such as its name) instead of its
134140ID.
135141
136- To configure which property should be shown to represent your entity, map the property containing
137- the name of the object with the ` https://schema.org/name ` type:
142+ To configure which property represents your entity, map the property that holds the name of the
143+ object with the ` https://schema.org/name ` type:
138144
139145``` php
140146// api/src/Entity/Person.php
0 commit comments