如何解决OroPlatform:覆盖 oro_datetime_widget 选项
上下文
我实际上是在尝试更改 OroDateTimeType::class
的时间输入的默认占位符。
例如,我想要文本 Horaires
而不是 Temps
。
这是我的 FormType 中的表单字段:
->add('expirationDate',OroDateTimeType::class,[
'label' => 'app.subscription.fields.expirationDate',])
在我的树枝视图中:
form_row(form.expirationDate)
问题
一开始,我尝试将 Symfony 4 placeholder
选项用于 DateTime 类型:https://symfony.com/doc/4.4/reference/forms/types/date.html#placeholder。它不起作用,因为 OroDateTime
使用不同的日期选择器并且它在加载时覆盖 Symfony 值:
{# vendor/oro/platform/src/Oro/Bundle/FormBundle/Resources/views/Form/fields.html.twig #}
{% block oro_datetime_widget %}
{% set dateValidation = {'Date' : {}} %}
{% set timeValidation = {'Time' : {}} %}
{% if required %}
{% set dateValidation = dateValidation|merge({'NotBlank' : {}}) %}
{% set timeValidation = timeValidation|merge({'NotBlank' : {}}) %}
{% endif %}
{% if attribute(attr,'class') is defined %}
{% set attrClass = attr['class'] %}
{% else %}
{% set attrClass = '' %}
{% endif %}
{% set options = {
view: 'oroui/js/app/views/datepicker/datetimepicker-view',nativeMode: isMobileVersion(),dateInputAttrs: {
placeholder: 'oro.form.choose_date'|trans,id: id,name: id,class: 'input-small datepicker-input ' ~ attrClass,'data-validation': dateValidation|json_encode(constant('JSON_FORCE_OBJECT')),'aria-live': 'assertive',autocomplete: 'off',autocorrect: 'off',autocapitalize: 'off'
},datePickerOptions: {
altFormat: 'yy-mm-dd',changeMonth: true,changeYear: true,yearRange: years|default('-80:+1'),showButtonPanel: true
},timeInputAttrs: {
placeholder: 'oro.form.choose_time'|trans,id: 'time_selector_' ~ id,name: 'time_selector_' ~ id,class: 'input-small timepicker-input ' ~ attrClass,'data-validation': timeValidation|json_encode(constant('JSON_FORCE_OBJECT'))
},timePickerOptions: {
}
} %}
{% set id = 'hidden_' ~ id %}
{% set attr = attr|merge({
'data-page-component-module': 'oroui/js/app/components/view-component','data-page-component-options': options|json_encode(constant('JSON_FORCE_OBJECT'))
}) %}
{{ block('datetime_widget') }}
{% endblock oro_datetime_widget %}
如果我更改 timeInputAttrs.placeholder
变量中的值 options
。有用。
但是,我想将此变量传递给我的特定表单字段,而不是全局。
更新
我最终选择全局更改我项目中的 oro.form.choose_time
翻译。
因此,在我的 Resources/translations/messages.fr_FR.yml
中,我创建了以下几行:
oro:
form:
choose_time: Horaires
auth:
description:
main: Baltimore
然后,我了解到翻译是在位于 var/cache/dev/translations/catalogue.fr_FR
的文件中生成的:
<?php
use Symfony\Component\Translation\MessageCatalogue;
$catalogue = new MessageCatalogue('fr_FR',array (
'messages' =>
array (
'oro.form.choose_time' => 'Temps','oro.auth.description.main' => 'Baltimore',
在这里,我可以看到应用了 oro.auth.description.main
更改,但键 oro.form.choose_time
的值仍然相同。
也许我有一个命令可以运行?
解决方法
覆盖 Oro 应用程序 UI 中任何文本的最简单方法是覆盖用于呈现它的消息的翻译。由于表单占位符也被翻译,您可以使用此技术。如果这是您对表单的唯一自定义,请遵循 this guide。
如果您想覆盖 HTML,可以按照 the template overriding guide 扩展模板。
但是,如果您想修改单个表单的标签,那么最好的方法是 extend the form type 并使用新选项覆盖单个表单字段。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。