Issue Bug Closed

#106151PHP warning for unset validators

Simon Praetorius 02/11/25, 11:31 updated 03/29/25, 16:07

Description

I’m getting the following PHP warning in TYPO3 v12:

> Core: Error handler (FE): PHP Warning: foreach() argument must be of type array|object, string given in /path/to/typo3/vendor/typo3/cms-form/Classes/Domain/Model/Renderable/AbstractRenderable.php line 153

My guess for the origin of this warning would be that the form in question uses __UNSET to disable validators for certain form variants:

-
  defaultValue: ''
  type: Email
  identifier: locationEmail
  label: Email
  variants:
    -
      identifier: locationEmail-optional
      condition: 'traverse(formValues, "useOperatorDataForLocation") == 1'
      validators: __UNSET
  validators:
    -
      identifier: EmailAddress
    -
      identifier: NotEmpty

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 8

  1. Christian Kuhn commented 02/11/25, 14:37

    quick feedback on reading the issue:

    imho: __UNSET is doomed in almost all cases and we should in general avoid relying on it, except there are very good reasons that can’t be solved differently and that are absolutely safe to use. we’ve run into various “__UNSET fucks up everything” cases in the past already.

    i don’t deny such a patch up front, but it should be argued wisely.

  2. Benni Mack commented and changed status New Needs Feedback 03/28/25, 17:07

    I agree, the magic __UNSET when using Yaml isn’t just built for this. @s2b I suggest to close this ticket. This will be a nightmare – on a lot of levels.

  3. Simon Praetorius commented 03/28/25, 17:11

    I agree that __UNSET should be avoided, but what would be a better alternative for this use case?

  4. Benni Mack commented 03/28/25, 17:28

    Simon Praetorius wrote in #note-3:
    > I agree that __UNSET should be avoided, but what would be a better alternative for this use case?

    Two Forms :(. (You can use includes + references btw, maybe that helps)

    In addition, you can revert the condition and put the validators in the variant (and only there)

    There are things in life that suck, and “YAML + EXT:form” is one them.

  5. Sébastien Delcroix commented 03/28/25, 18:17

    Benni Mack wrote in #note-4:
    > Two Forms :(. (You can use includes + references btw, maybe that helps)
    >
    Do you have an example of includes + references in this case ? :)

  6. Benni Mack commented 03/28/25, 18:22

    > Do you have an example of includes + references in this case ? :)

    I don’t use EXT:form myself. But here might be some examples regarding anchors

    -
    myvalidators: &validators
        - identifier: EmailAddress
        - identifier: NotEmpty
    
    ....
    
      defaultValue: ''
      type: Email
      identifier: locationEmail
      label: Email
      variants:
        -
          identifier: locationEmail-optional
          condition: 'traverse(formValues, "useOperatorDataForLocation") == 1'
          validators: __UNSET
      validators: *id001

    This way, you can re-use parts of the yaml, without bloating it up (the & = anchor, and * is a reference – that’s native YAML)

    the imports are TYPO3-specific:

    imports:
      - { resource: 'EXT:my_ext/Resources/Private/DefaultForm.form.yaml' }
    ...
    
      validators:
        - identifier: EmailAddress
        - identifier: NotEmpty

    This way you have one main form (for inclusion), and set validators in the actual form.yamls

  7. Sébastien Delcroix commented 03/28/25, 19:11

    Oh right, of course ! I’ve completely forgotten these YAML features I used while ago in our Gitlab CI/CD configs ^^

    Thanks a lot for reminding me ! ;)

  8. Garvin Hicking commented and changed status Needs Feedback Closed 03/29/25, 16:07

    This sounds like a viable solution? Closing due to this, but let me know if it needs to stay open.