blast-project / utils-bundle
All kinds of goodies for the BlastCoreBundle
Installs: 5 386
Dependents: 8
Suggesters: 0
Security: 0
Stars: 1
Watchers: 4
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=7.1
- blast-project/core-bundle: 0.6.4
- sonata-project/doctrine-orm-admin-bundle: >=3.1
- stfalcon/tinymce-bundle: >=2.1
- symfony/symfony: >=3.2
Requires (Dev)
- phpunit/phpunit: ^6.4
- symfony/phpunit-bridge: >=3.2
Suggests
- blast-project/outer-extension-bundle: Extend your doctrine entities from the outside
This package is not auto-updated.
Last update: 2024-10-26 20:37:46 UTC
README
Features
Blast Choices
Documentation to be writen
Blast Hooks
This bundle introduce a hook feature that is really basic hook management.
You can define in your views any hook you want.
Declare the hook target location in a view
{# myTemplate.html.twig #} <div> <h1>Here my custom hook</h1> {{ blast_hook('my.custom.hook', {'someParameters': myVar}) }} </div>
A hook can be declared without using any parameters. If so, the « hook block » won't have any parameters defined in handleParameters
's method parameter (var $hookParameters
will be an empty array).
Declare your Hook class
This class will manage rendering of the hook content by setting view parameters
(act as a controller)
<?php namespace MyBundle\Hook\MyCustomHook; use Blast\UtilsBundle\Hook\AbstractHook; class MyCustomHookExample extends AbstractHook { protected $hookName = 'my.custom.hook'; protected $template = 'MyBundle:Hook:my_custom_hook_example.html.twig'; public function handleParameters($hookParameters) { $this->templateParameters = [ 'someViewParameter' => 'a value that will be passed to the twig view' ]; } }
Note: you can get the current hook name (configured in service definition) in attribute AbstractHook::hookName
ans the configured template in AbstractHook::template
Register the hook class as service
my_bundle.hook.my_custom_hook_example: class: MyBundle\Hook\MyCustomHook\MyCustomHookExample tags: - { name: blast.hook, hook: my.custom.hook, template: MyBundle:Hook:my_custom_hook_example.html.twig }
The hook configuration are sets in the service tag :
name
: the service tag name (must beblast.hook
)hook
: the target hook where the « block » will be renderedtemplate
: the twig template of the « block »
Please don't forget the tag blast.hook
in order to register your service as a hook
Create your hook template
{# MyBundle:Hook:my_custom_hook_example.html.twig #} <p> Here's my first custom hook, with a view var : {{ someViewParameter }} ! </p>
And voila, you should have this rendered content :
<div> <h1>Here my custom hook</h1> <p> Here's my first custom hook, with a view var : a value that will be passed to the twig view ! </p> </div>
Blast Custom Filters
Enable the feature in config.yml
# app/config/config.yml blast_utils: features: customFilters: enabled: true
Optionnaly, you can define your own customFilter entity by setting it as below (don't forget to set the associated repository in order to override createNewCustomFilter
method) :
# app/config/config.yml blast_utils: features: customFilters: enabled: true class: MyBundle\Entity\MyCustomFilter
You only have to set your User class entity in application config.yml (see https://symfony.com/doc/current/doctrine/resolve_target_entity.html for more informations)
# app/config/config.yml doctrine: # ... orm: # ... resolve_target_entities: Blast\CoreBundle\Model\UserInterface: MyBundle\Entity\MyUser
If you're using Sylius, setting the doctrine.orm resolve_target_entities
key will not work because Sylius is already using this system. You can declare your Interface / Entity replacement within SyliusResource
configuration :
# app/config/config.yml sylius_resource: resources: blast.utils: # this is an arbitrary key classes: model: MyBundle\Entity\MyUser interface: Blast\CoreBundle\Model\UserInterface
Blast User Interface
In order to set User mapping with utils entity, the mapping with Interface is used.
There are 2 ways for configuring the real class that will replace the UserInterface :
Using Sylius
declare, via resources, the class that will replace the model interface
sylius_resource: resources: blast.utils: classes: model: MyBundle\Entity\MyRealUser interface: Blast\CoreBundle\Model\UserInterface
Using Syfony's Doctrine target entity resolver :
doctrine: # ... orm: #... resolve_target_entities: Blast\CoreBundle\Model\UserInterface: MyBundle\Entity\MyRealUser