blast-project/utils-bundle
Composer 安装命令:
composer require blast-project/utils-bundle
包简介
All kinds of goodies for the BlastCoreBundle
README 文档
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
统计信息
- 总下载量: 5.42k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0
- 更新时间: 2016-12-02