Download the PHP package umanit/block-bundle without Composer
On this page you can find all versions of the php package umanit/block-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download umanit/block-bundle
More information about umanit/block-bundle
Files in umanit/block-bundle
Package block-bundle
Short Description Doctrine Block management made easy
License MIT
Homepage https://github.com/umanit/block-bundle
Informations about the package block-bundle
Umanit Block Bundle
Doctrine Block managment made easy.
- Simple implementation
- Flexible
- Orderable Blocks
- Database consistent
- User friendly
- Dev friendly
Philosophy
Usually when dealing with blocks, developers lose their database consistency because they have to store many block types in a single table. The most common way of storing many types of blocks in one single table is to store them in a json column.
We think json is bad for database consistency and performances. Searching, indexing, managing relations, primary and unique keys... You name it, none of them is possible with json.
UmanitBlockBundle intends to solve this problem by giving back their entities to the developers.
Front requirements
- Use Symfony UX
Install
Register the bundle to your config/bundles.php
Add one of the Twig's form theme
Add @umanit/block-bundle
dev-dependency in your package.json
. This part is automatically done if you use Flex in
your projet.
Add stimulus controllers to your assets/controllers.json
. This part is automatically done if you use Flex in your
projet.
Don't forget to install the JavaScript dependencies as well and compile
Warning
Your Stimulus app must be running on your back end if you want to use this bundle: make sure the bootstrap.js
file
that starts it is imported.
Your script must be loaded using encore_entry_script_tags()
.
Here are exemples on how to do that depending on your back end library, given an admin.js
file on your end:
EasyAdmin 4
In your DashboardController
, you can do it this way:
Sonata Admin 4
Configuration
app.js
needs to import yourbootstrap.js
, that loads both your own Stimulus controllers and those of Block Bundle in your Stimulus backend application- if using CKEditor, see the dedicated documentation
You'll have to modify your webpack.config.js
to allow your Stimulus controllers to work in your Sonata backend:
Usage
Terminology
- A
Block
is a simple Doctrine entity that implementsUmanit\BlockBundle\Model\BlockInterface
. - A
Block Manager
is a service used to administrate and render aBlock
. - A
Panel
is a Doctrine entity that contains a collection of orderedBlock
instances.
Create an entity containing the Panel
Usually, you'll have a content entity (here we'll call it Page
) having one or more Panels
.
Next, use the provided PanelType
form to administrate the Page
content.
Every block manager is available by default, if you want to filter them, you can give an option authorized_blocks
, an
array of all the block types allowed to be selected, or unauthorized_blocks
, an array of all the block types not
allowed to be selected.
Read further for integration with EasyAdmin 4 and defining a PanelField
in your
CRUDController
Create a Block entity and its Block Manager
Start by creating your Block
entity which should extends the bundle Block
entity, like the following example:
Then, create a Block Manager
service and its FormType
which should extend AbstractBlockType
. This service will
define the form used to administrate your Block
. It will also allow you to define the rendering of the Block
in the
front end.
Finally, tag your Block Manager
with umanit_block.manager
.
Render your blocks
Use the twig function umanit_block_render
to render each of your blocks.
umanit_block_render
will find the right BlockManager
and call its render
method.
You can pass an array of parameters to umanit_block_render
. This parameters will be passed to the render
method of
the BlockManager
.
Embedding a panel within a collection item
Block Bundle uses Stimulus, so you don't need to do anything on your end: controllers will be instantiated as they're added to the DOM.
Integration with UmanitTranslationBundle
This bundle is fully compatible with UmanitTranslationBundle. Once
translating a Panel
, all the Block
instances and their properties will also be translated. If you need a locale
parameter in you BlockManager
form (to filter an EntityType
for example), pass the parameter to the PanelType
like
so:
Integration with EasyAdmin 4
Registering the provided form theme
In your DashboardController
:
Using the PanelField
If defining a CrudController
, you can use the provided PanelField
:
As with PanelType
, you can define either authorized_blocks
or unauthorized_blocks
if you need to restrict the available block list to some chosen options.
Using a form type from EasyAdmin within a block
You might want to use FileUploadType
, for example, in your blocks.
Block Bundle only works with Symfony form types, which means you will not be able to use EA fields in them and leverage
their powerful configurators. You can, however, still use the associated form type in your block form type but you might
need to get your hands dirty with the options.
The block.js
Stimulus controllers dispatches the ea.collection.item-added
after a block has been added to the DOM,
so EA JS will be bound to it.
CKEditor
Read the dedicated CKEditor documentation if you want to use it in your blocks
All versions of block-bundle with dependencies
symfony/translation-contracts Version ^1.1|^2.3|^3.0
symfony/form Version ^4.4|^5.2|^6.0
symfony/framework-bundle Version ^4.4|^5.2|^6.0
symfony/validator Version ^4.4|^5.2|^6.0
doctrine/doctrine-bundle Version ^1.6|^2.1
doctrine/orm Version ^2.5