Customizing the Admin

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.

API Platform Admin のカスタマイズは簡単で慣用的です。このツールを使用すると、管理可能にする必要があるリソース タイプのリストから、すべての入力またはボタンに至るまで、すべてをカスタマイズできます。

To do so, you can use the React components provided by API Platform Admin itself, React Admin, Material UI, community libraries, or write your own.

これを行うには、API Platform Admin 自体、React Admin、Material UI、コミュニティ ライブラリによって提供される React コンポーネントを使用するか、独自に作成することができます。

Customizing the Admin's Main Page and the Resource List

By default, API Platform Admin automatically builds a tailored Resource component (and all its appropriate children) for each resource type exposed by a web API. Under the hood it uses the @api-platform/api-doc-parser library to parse the API documentation. The API documentation can use Hydra, OpenAPI and any other format supported by the library. Resources are listed in the order they appear in the machine-readable documentation.

デフォルトでは、API プラットフォーム管理者は、ウェブ API によって公開されるリソース タイプごとに調整されたリソース コンポーネント(およびそのすべての適切な子コンポーネント)を自動的に構築します。内部では、@api-platform/api-doc-parser ライブラリを使用して API を解析します。ドキュメンテーション。API ドキュメンテーションでは、Hydra、OpenAPI、およびライブラリでサポートされているその他の形式を使用できます。リソースは、機械可読ドキュメンテーションに表示される順序でリストされています。

However, it's also possible to display only specific resources, and to order them, while still benefiting from all discovery features provided by API Platform Admin. To cherry-pick the resources to make available through the admin, pass a list of <ResourceGuesser> components as children of the root component:

ただし、API プラットフォーム管理者が提供するすべての検出機能を活用しながら、特定のリソースのみを表示して注文することも可能です。ルート コンポーネント:

import { HydraAdmin, ResourceGuesser } from "@api-platform/admin";

export default () => (
  <HydraAdmin entrypoint="https://demo.api-platform.com">
    <ResourceGuesser name="books" />
    <ResourceGuesser name="reviews" />

    {/* While deprecated resources are hidden by default, using an explicit ResourceGuesser component allows to add them back. */}
    <ResourceGuesser name="parchments" />
  </HydraAdmin>
);

Instead of using the <ResourceGuesser> component provided by API Platform Admin, you can also pass custom React Admin's Resource components, or any other React components that are supported by React Admin's Admin.

API Platform Admin によって提供されるコンポーネントを使用する代わりに、カスタムの React Admin の Resource コンポーネント、または React Admin の Admin によってサポートされるその他の React コンポーネントを渡すこともできます。

Customizing the List View

The list view can be customized following the same pattern:

リスト ビューは、同じパターンに従ってカスタマイズできます。

import {
  HydraAdmin,
  ResourceGuesser,
  ListGuesser,
  FieldGuesser
} from "@api-platform/admin";

const ReviewsList = props => (
  <ListGuesser {...props}>
    <FieldGuesser source="author" />
    <FieldGuesser source="book" />

    {/* While deprecated fields are hidden by default, using an explicit FieldGuesser component allows to add them back. */}
    <FieldGuesser source="letter" />
  </ListGuesser>
);

export default () => (
  <HydraAdmin entrypoint="https://demo.api-platform.com">
    <ResourceGuesser name="reviews" list={ReviewsList} />
    {/* ... */}
  </HydraAdmin>
);

In this example, only the fields author, book and letter (that is hidden by default because it is deprecated) will be displayed. The defined order will be respected.

この例では、フィールド author、book、および letter (廃止されたため、デフォルトでは非表示になっています) のみが表示されます。定義された順序が尊重されます。

In addition to the <FieldGuesser> component, all React Admin Fields components can be passed as children of <ListGuesser>.

コンポーネントに加えて、すべての React Admin Fields コンポーネントを の子として渡すことができます。

Customizing the Show View

For the show view:

ショー ビューの場合:

import {
  HydraAdmin,
  ResourceGuesser,
  ShowGuesser,
  FieldGuesser
} from "@api-platform/admin";

const ReviewsShow = props => (
  <ShowGuesser {...props}>
    <FieldGuesser source="author" />
    <FieldGuesser source="book" />
    <FieldGuesser source="rating" />

    {/* While deprecated fields are hidden by default, using an explicit FieldGuesser component allows to add them back. */}
    <FieldGuesser source="letter" />

    <FieldGuesser source="body" />
    <FieldGuesser source="publicationDate" />
  </ShowGuesser>
);

export default () => (
  <HydraAdmin entrypoint="https://demo.api-platform.com">
    <ResourceGuesser name="reviews" show={ReviewsShow} />
    {/* ... */}
  </HydraAdmin>
);

In addition to the <FieldGuesser> component, all React Admin Fields components can be passed as children of <ShowGuesser>.

コンポーネントに加えて、すべての React Admin Fields コンポーネントを の子として渡すことができます。

Customizing the Create Form

Again, the same logic applies to forms. Here is how to customize the create form:

ここでも、同じロジックがフォームに適用されます。作成フォームをカスタマイズする方法は次のとおりです。

import {
  HydraAdmin,
  ResourceGuesser,
  CreateGuesser,
  InputGuesser
} from "@api-platform/admin";

const ReviewsCreate = props => (
  <CreateGuesser {...props}>
    <InputGuesser source="author" />
    <InputGuesser source="book" />
    <InputGuesser source="rating" />

    {/* While deprecated fields are hidden by default, using an explicit InputGuesser component allows to add them back. */}
    <InputGuesser source="letter" />

    <InputGuesser source="body" />
    <InputGuesser source="publicationDate" />
  </CreateGuesser>
);

export default () => (
  <HydraAdmin entrypoint="https://demo.api-platform.com">
    <ResourceGuesser name="reviews" create={ReviewsCreate} />
    {/* ... */}
  </HydraAdmin>
);

In addition to the <InputGuesser> component, all React Admin Input components can be passed as children of <CreateGuesser>.

コンポーネントに加えて、すべての React Admin Input コンポーネントを の子として渡すことができます。

For instance, using an autocomplete input is straightforward, check out the dedicated documentation entry!

たとえば、オートコンプリート入力の使用は簡単です。専用のドキュメント エントリを確認してください。

Customizing the Edit Form

Finally, you can customize the edit form the same way:

最後に、同じ方法で編集フォームをカスタマイズできます。

import {
  HydraAdmin,
  ResourceGuesser,
  EditGuesser,
  InputGuesser
} from "@api-platform/admin";

const ReviewsEdit = props => (
  <EditGuesser {...props}>
    <InputGuesser source="author" />
    <InputGuesser source="book" />
    <InputGuesser source="rating" />

    {/* While deprecated fields are hidden by default, using an explicit InputGuesser component allows to add them back. */}
    <InputGuesser source="letter" />

    <InputGuesser source="body" />
    <InputGuesser source="publicationDate" />
  </EditGuesser>
);

export default () => (
  <HydraAdmin entrypoint="https://demo.api-platform.com">
    <ResourceGuesser edit={ReviewsEdit}/>
    {/* ... */}
  </HydraAdmin>
);

In addition to the <InputGuesser> component, all React Admin Input components can be passed as children of <EditGuesser>.

コンポーネントに加えて、すべての React Admin Input コンポーネントを の子として渡すことができます。

For instance, using an autocomplete input is straightforward, checkout the dedicated documentation entry!

たとえば、オートコンプリート入力の使用は簡単です。専用のドキュメント エントリをチェックしてください。

Going Further

API Platform is built on top of React Admin. You can use all the features provided by the underlying library with API Platform Admin, including support for authentication, authorization and deeper customization.

API プラットフォームは、React Admin の上に構築されています。認証、承認、詳細なカスタマイズのサポートなど、基礎となるライブラリによって提供されるすべての機能を API Platform Admin で使用できます。

To learn more about these capabilities, refer to the React Admin documentation.

これらの機能の詳細については、React 管理ドキュメントを参照してください。