【问题标题】:Prestashop 1.7 - Override Symfony form constraintsPrestashop 1.7 - 覆盖 Symfony 表单约束
【发布时间】:2021-09-27 04:35:33
【问题描述】:

上下文

我正在尝试更改产品名称属性的约束并将字段长度增加到 300 个字符。

问题

src/PrestaShopBundle/Form/Admin/Product/ProductInformation.php,我可以改:

->add('name', TranslateType::class, [
    'type' => FormType\TextType::class,
    'options' => [
        'constraints' => [
            new Assert\Regex([
                'pattern' => '/[<>;=#{}]/',
                'match' => false,
            ]),
            new Assert\NotBlank(),
            new Assert\Length(['min' => 3, 'max' => 128]),
        ],
    ],
])

->add('name', TranslateType::class, [
    'type' => FormType\TextType::class,
    'options' => [
        'constraints' => [
            new Assert\Regex([
                'pattern' => '/[<>;=#{}]/',
                'match' => false,
            ]),
            new Assert\NotBlank(),
            new Assert\Length(['min' => 3, 'max' => 300]),
        ],
    ],
])

而且.. 它有效。但是如果 PrestaShop 更新会发生什么。我需要一种更优雅的方式来做到这一点。

更新#1

官方 PrestaShop Github 存储库中有 PR。我正在等待答案:https://github.com/PrestaShop/PrestaShop/issues/23977

【问题讨论】:

标签: symfony prestashop symfony4 prestashop-1.7


【解决方案1】:

经典的方式是覆盖模型,在本例中是/override/classes/Product.php

在静态 $definition 上,您将名称字段、大小属性从 128 更改为 300

【讨论】:

  • 谢谢,但我已经这样做了。我的问题涉及长度限制..
猜你喜欢
  • 1970-01-01
  • 2021-01-06
  • 2013-04-11
  • 1970-01-01
  • 2017-03-28
  • 1970-01-01
  • 1970-01-01
  • 2017-03-10
  • 1970-01-01
相关资源
最近更新 更多