Improve DX of decaring use of constraints in annotations

Created on 16 March 2014, over 11 years ago
Updated 15 August 2025, 15 days ago

Coming at you from #2145103: Provide non-configurable field types for entity created, changed and timestamp fields β†’ .

  1. +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/ChangedItem.php
    @@ -0,0 +1,33 @@
    + *   constraints = {
    + *     "ComplexData" = {"value" = {"EntityChanged" = {}}}
    + *   }
    

    I literally have no idea how to translate that into English. Looks like jibran had earlier in that issue, too...

  2. +++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Email.php
    @@ -17,7 +17,7 @@
    - *   constraints = {"Email" = TRUE}
    + *   constraints = {"Email" = {}}
    

    ...this is just silly. I see that it saves us a 3-line hack in TypedDataManager, but it really makes the DX totally non-intuitive. (And easy to mis-type, too... accidentally leaving off a }, typing a ] instead, etc.)

    I was unsuccessful in googling for any reference material on Drupal's entity constraints API. so I feel a little out of my depth to make concrete suggestions.

    But I know (or think I know) that somewhere under the hood we're using Symfony validator for this, but our annotations look nothing like the examples in their documentation at http://symfony.com/doc/current/book/validation.html. There, they do something more like:

    /**
      * @Assert\Email
      */
    

    or

    /**
     * @Assert\ComplexData('EntityChanged')
     */
    

    ...which is easy enough to read/understand.

    Does it make sense to move to that model, or is there another/better way to clean this up?

πŸ“Œ Task
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

typed data system

Created by

πŸ‡¨πŸ‡¦Canada webchick Vancouver πŸ‡¨πŸ‡¦

Live updates comments and jobs are added and updated live.
  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for creating this issue to improve Drupal.

    We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024