Prestashop 1.7 - 覆盖 Symfony 表单约束

问题描述

上下文

我正在尝试更改产品名称属性的约束并将字段长度增加到 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','max' => 300]),])

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

更新 #1

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

解决方法

经典的方法是覆盖模型,在这种情况下是/override/classes/Product.php

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