Add a recipe for API Platform Admin

This commit is contained in:
Kévin Dunglas
2018-12-08 21:47:20 +01:00
parent 1714b9f050
commit 40e6b96a0f
6 changed files with 50 additions and 0 deletions
@@ -0,0 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { HydraAdmin } from '@api-platform/admin';
const entrypoint = document.getElementById('api-entrypoint').innerText;
ReactDOM.render(<HydraAdmin entrypoint={entrypoint}/>, document.getElementById('api-platform-admin'));
@@ -0,0 +1,5 @@
admin:
path: /admin
controller: Symfony\Bundle\FrameworkBundle\Controller\TemplateController
defaults:
template: admin.html.twig
@@ -0,0 +1,8 @@
{
"copy-from-recipe": {
"assets/": "assets/",
"config/": "%CONFIG_DIR%/",
"templates/": "templates/"
},
"aliases": ["api-admin", "api-platform-admin", "react-admin"]
}
@@ -0,0 +1,16 @@
<bg=blue;fg=white> </>
<bg=blue;fg=white> To finish the install </>
<bg=blue;fg=white> </>
* Your admin is almost ready:
1. Install the JavaScript dependencies by running <comment>yarn add @api-platform/admin</comment>
2. Go in <comment>webpack.config.js</comment> and <info>uncomment</info> the following lines:
Encore
// ...
.enableReactPreset()
.addEntry('admin', './assets/js/admin.js')
* Mark any entity with the <comment>@ApiResource</comment> annotation, it appears in the admin!
* Using MakerBundle? Try <info>php bin/console make:entity --api-resource</info>
@@ -0,0 +1,10 @@
{% extends 'base.html.twig' %}
{% block title %}API Platform Admin{% endblock %}
{% block body %}<div id="api-platform-admin"></div>{% endblock %}
{% block javascripts %}
<script type="text/plain" id="api-entrypoint">{{ path('api_entrypoint') }}</script>
{{ encore_entry_script_tags('admin') }}
{% endblock %}
@@ -46,6 +46,10 @@ Encore
// uncomment if you're having problems with a jQuery plugin
//.autoProvidejQuery()
// uncomment if you use API Platform Admin (composer req api-admin)
//.enableReactPreset()
//.addEntry('admin', './assets/js/admin.js')
;
module.exports = Encore.getWebpackConfig();