blast-project / utils-bundle
BlastCoreBundle的各种实用工具
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-09-14 20:04:10 UTC
README
功能
Blast选择
待编写的文档
Blast钩子
本捆绑包引入了一个基本的钩子管理功能。
您可以在视图中定义任何想要的钩子。
在视图中声明钩子目标位置
{# myTemplate.html.twig #} <div> <h1>Here my custom hook</h1> {{ blast_hook('my.custom.hook', {'someParameters': myVar}) }} </div>
钩子可以不使用任何参数进行声明。如果这样,"钩子块"在"handleParameters"方法参数中不会定义任何参数(变量$hookParameters
将是一个空数组)。
声明您的钩子类
此类将通过设置视图参数
来管理钩子内容的渲染(充当控制器)
<?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' ]; } }
注意:您可以在属性AbstractHook::hookName
中获取当前钩子名称(在服务定义中配置),以及在AbstractHook::template
中配置的模板。
将钩子类注册为服务
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 }
钩子配置设置在服务标签中
name
:服务标签名称(必须是blast.hook
)hook
:将要渲染的"块"的目标钩子template
:"块"的twig模板
请不要忘记使用标签blast.hook
来注册您的服务作为钩子
创建您的钩子模板
{# MyBundle:Hook:my_custom_hook_example.html.twig #} <p> Here's my first custom hook, with a view var : {{ someViewParameter }} ! </p>
然后,您应该有这个渲染内容
<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自定义过滤器
在config.yml中启用此功能
# app/config/config.yml blast_utils: features: customFilters: enabled: true
可选地,您可以定义自己的customFilter实体,如下设置(不要忘记设置相关的存储库以覆盖createNewCustomFilter
方法)
# app/config/config.yml blast_utils: features: customFilters: enabled: true class: MyBundle\Entity\MyCustomFilter
您只需在应用程序config.yml中设置您的User类实体(有关更多信息,请参阅https://symfony.ac.cn/doc/current/doctrine/resolve_target_entity.html)
# app/config/config.yml doctrine: # ... orm: # ... resolve_target_entities: Blast\CoreBundle\Model\UserInterface: MyBundle\Entity\MyUser
如果您正在使用Sylius,则设置doctrine.orm resolve_target_entities
密钥将不起作用,因为Sylius已经使用了此系统。您可以在SyliusResource
配置中声明您的Interface / Entity替换
# 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用户界面
为了设置与utils实体的User映射,使用Interface进行映射。
有2种方式来配置将要替换UserInterface的实际类
使用Sylius
通过资源声明将替换模型接口的类
sylius_resource: resources: blast.utils: classes: model: MyBundle\Entity\MyRealUser interface: Blast\CoreBundle\Model\UserInterface
使用Syfony的Doctrine目标实体解析器
doctrine: # ... orm: #... resolve_target_entities: Blast\CoreBundle\Model\UserInterface: MyBundle\Entity\MyRealUser