0

Is it possible to change behavior of in-built field with a module? I am trying to change // Apply static translations part of _normalizeValueInternal function in Table.php https://github.com/craftcms/cms/blob/5744e952204802a424abed96270ea52631cd61ea/src/fields/Table.php#L443

I can make it work if I edit the core Table.php file, but that would be overwritten each update. So I am thinking about module.

I can only find guides to create new custom field, but nothing about changing built-in fields.

Thanks.

5
  • 1
    You can't really modify the internal logic of fields, you can only modify the business logic using event hooks, or extend a built-in field to modify it as needed. What problem are you trying to solve?l
    – MoritzLost
    Commented Oct 16, 2023 at 14:28
  • As described here github.com/craftcms/cms/discussions/… I am trying to change target language of static translation of Row Headings in Table field in backend. So instead of CP language it's determined by site language. In linked comment there is also code that would need to be changed. It's just "good to have" nothing critical.
    – Foxtrot
    Commented Oct 16, 2023 at 14:43
  • Hm, looks tricky. Not sure if there's an easy way to change that behaviour without extending the field. Might be able to overwrite the labels using JavaScript, though that's not a great solution either.
    – MoritzLost
    Commented Oct 16, 2023 at 15:39
  • Maybe try to make custom field that extends table field class? Your class could overwrite method that contains piece of logic that you want to change. After you create new class you would only need to register it (you can check field plugins to find how they register their own fields) so it is selectable as field type. Commented Oct 16, 2023 at 17:58
  • Yeah, I know I can make custom field that extends the built-in field. That's why I am asking if it's possible to directly change built-in field or if custom field is the only option. But it looks like there is no easy direct way to do it without making custom field. Thanks for answers.
    – Foxtrot
    Commented Oct 17, 2023 at 9:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.