Skip to content

Add a recipe for API Platform Admin #503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
3 commits merged into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions api-platform/admin-pack/1.0/assets/js/admin.js
Original file line number Diff line number Diff line change
@@ -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'));
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
admin:
path: /admin
controller: Symfony\Bundle\FrameworkBundle\Controller\TemplateController
defaults:
template: admin.html.twig
8 changes: 8 additions & 0 deletions api-platform/admin-pack/1.0/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"copy-from-recipe": {
"assets/": "assets/",
"config/": "%CONFIG_DIR%/",
"templates/": "templates/"
},
"aliases": ["api-admin", "api-platform-admin", "react-admin"]
}
16 changes: 16 additions & 0 deletions api-platform/admin-pack/1.0/post-install.txt
Original file line number Diff line number Diff line change
@@ -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 @babel/preset-react</comment>
2. Edit <comment>webpack.config.js</comment> and <info>uncomment</info> the following lines:

Encore
// ...
.enableReactPreset()
.addEntry('admin', './assets/js/admin.js')

* Mark entities you want in the admin with the <comment>@ApiResource</comment> annotation, it appears in the admin!

* Using MakerBundle? Try <info>php bin/console make:entity --api-resource</info>
10 changes: 10 additions & 0 deletions api-platform/admin-pack/1.0/templates/admin.html.twig
Original file line number Diff line number Diff line change
@@ -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 %}
4 changes: 4 additions & 0 deletions symfony/webpack-encore-bundle/1.0/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();