Review main Abandoned

73632[POC][FEATURE] Introduce TCA field transformers

Andreas Kienast CR 0 V 0 Hard +591 −19 updated 05/03/23, 09:21

Commit message

In historical context, TCA provides an `eval` configuration used for two
different concerns:

* data modification (trim, intval, etc.)
* data validation (required, email, etc.)

These options are a list of hardcoded arbitrary strings used in
DataHandler and FormEngine. Extension of such evaluations is possible,
but is rather clumsy as it requires a custom class that doesn't
implement an interface, also usage in TCA requires the FQCN in a CSV of
strings.

This patch introduces field transformers that perform modifications
to the incoming input value, like trimming data or change its casing.
Such modifiers are used within TCA in a new `transformers` array for
both directions, persistence and retrieval (hint: to be implemented).

The goal of these modifies are:
 * implement a standardized interface
 * optionally load a JavaScript module to perform modifications on
   client-side, where applicable (password hashing obviously isn't)
 * easier testing
 * trim (pun intended) the list of eval options and make eval obsolete
   in future

TODO:
 * implement date related transformers
 * implement double2 transformer
 * use "reverse" transformations in FormEngine

Review

  • Code review CR 0
  • Verified V 0

Files 17

Review log 911

  1. Andreas Kienast uploaded patch set 1 02/21/22, 17:38

  2. Martin Kutschker commented on patch set 1 02/21/22, 17:51

    Configuration of modifiers is very good. I don't like to write a padding modifier for all lenght and character combinations. "Modifier" may not be the best name for it. IMHO it lacks the information of the direction which is "input". And I like "transformation" better: so I'd go for "InputTransformationInterface". Why would the JS module be required? Will the transformation happen a the client AND the server side? How will double transformation be prevented?

    ModifierInterface.php:22

    The return value seems quite restriced. What about floats? Can booleans and Date objects be handled at this point?
  3. core-ci voted on patch set 1 V -1 02/21/22, 17:53 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/24001

  4. Andreas Kienast commented on patch set 1 02/21/22, 18:05

    Reply

    Currently, FormEngine applies transformations as well so a backend user will see an immediate effect, which is then submitted to DataHandler in the end. It's true this will cause a double transformation, but this wasn't an issue in the past, as a second transformation of the same type shouldn't alter the value again.

    ModifierInterface.php:22 Reply Unresolved

    That's true, I just took what I've noticed by a quick look. The current "eval" system cannot handle bools and DateType types, but I don't see a reason right now to not allow it in the future.
  5. Martin Kutschker commented on patch set 1 02/21/22, 19:10

    Reply

    Not if it's to be type safe. In the examples of the first commit we have an integer modifier that accepts a string and returns an int. But of course we can cast all values again to strings. Perhaps the data flow is currently wrong. What if the modifier would return a value object instead of a scalar? Then the DataHandler could accept either a string to modify or an aleady modified value.
  6. Andreas Kienast commented on patch set 1 02/21/22, 19:28

    Reply

    I get your point. I've made the types less strict in my code right now, Symfony does the same with their Data Transformers (https://symfony.com/doc/current/form/data_transformers.html). Talking about what Symfony does: sometimes a "transform back" doesn't make much sense, e.g. for trimming or password hashing, hence I'd make such transformation optional via an interface (FromPersistenceTransformerInterface or alike).
  7. Andreas Kienast uploaded patch set 2 02/21/22, 21:15

  8. Martin Kutschker commented on patch set 1 02/21/22, 21:21

    Reply Unresolved

    I know. I assume it depends on the purpose of the transformation. Is it directly from external representation to storage presentation, ie human readable strings to database types? Or is it a two-step process: human readable to PHP type, PHP type to database type. Which reminds me to question to usefulness of the transformations of "eval" that do type juggling: "int" and "double2". Both are already defined by the database type.
  9. core-ci voted on patch set 2 V -1 02/21/22, 21:23 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/24014

  10. Benni Mack commented on patch set 2 02/22/22, 09:15

    JavaScriptModuleInterface.php:20 Unresolved

    maybe this should rather be a "ClientTransformationInterface"?
  11. Benni Mack abandoned the change 05/03/23, 09:21

    not in use right now