crudadmin/gutenberg adds the WordPress Gutenberg block editor as the gutenberg field type. The field stores the block markup. On the website, reading the field returns rendered HTML.
The package is a fork of Laraberg, licensed under GPL-3.0-or-later.
Requirements
Installation
admin:update publishes the editor into public/vendor/gutenberg and adds the directory to .gitignore. Publish it manually with:
admin:update after each update of the package, as the deploy script does.
The editor is built into the package, your project needs no npm build. The administration loads its scripts and styles automatically.
Adding the field
app/Models/Page.php
- The column is a nullable
text. - Gutenberg fields are hidden in the table of rows.
- Only one editor can be active on a page. Further Gutenberg fields, including other languages of a localized field, show a button which switches the editor to them.
Rendering on the website
Outside the administration, the field returns HTML. Print it unescaped, and add the styles of the blocks to the<head> with @gutenberg:
resources/views/layouts/app.blade.php
resources/views/pages/show.blade.php
<div class="crudadmin-gutenberg-wrapper">, and each top-level block in <div class="g-block-wrapper" data-block="core/paragraph">. Empty content returns null. Change the classes in the config:
config/admin.php
Rendering manually
Embeds
Embed blocks are rendered with the HTML of the provider, cached forever. The editor offers YouTube, Vimeo, Instagram, Facebook and the generic embed block.Images and videos
The media button of the blocks opens the file browser of the administration. Files dropped into the editor are uploaded touploads/editor/images/shared and compressed. Limit the accepted types in the config:
config/admin.php
Upgrading from 2.x
- React 18 replaces React 16. Rebuild your own blocks against it.
- CrudAdmin 5 or newer is required, which renders the field on the website.
- Custom integrations switch the active editor with a window event instead of the event bus of CrudAdmin 5 resources: