Entity is not validated prior to being saved

Created on 11 April 2019, about 6 years ago
Updated 30 October 2023, over 1 year ago

Currently it appears the field values are set and the entity is saved without validation.
The attached patch adds support for $entity->validate() prior to saving.
More info: https://www.drupal.org/docs/8/api/entity-validation-api/entity-validatio... β†’
With thanks for the useful module.

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡³πŸ‡ΏNew Zealand davidwhthomas

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.4 + Environment: PHP 8.2 & MySQL 8
    last update over 1 year ago
    8 pass
  • πŸ‡§πŸ‡ͺBelgium falc0

    Going further on the patch in #4:

    Views_bulk_operations expects $result['message'] to be a MarkupInterface. I changed the patch for this and added the type "error" so the messages get the correct status.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.1 + Environment: PHP 8.2 & MySQL 8
    last update over 1 year ago
    8 pass
  • πŸ‡§πŸ‡ͺBelgium rp7

    Expanded the patch to limit validation errors to only the ones that the user is able to edit, consistent with content entity forms (https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Core/Entity/ContentEntityForm.php?ref_type=heads#L212)

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.1 + Environment: PHP 8.2 & MySQL 8
    last update over 1 year ago
    8 pass
  • πŸ‡§πŸ‡ͺBelgium rp7

    A small improvement in that the field label is nog also mentioned in the error message, which makes it easier for the user to know which field is causing the error message. As mentioned before, the error reporting is still very much barebones and I expect the work done in #1327632: Support action specific status message reporting. β†’ could help us here.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    @rp7 could you turn this into a MR?

    Furthermore I' unsure if it should't allow to opt-out. Perhaps adding a setting "Validate entity" which is prechecked, could make sense?

  • Status changed to Needs work 8 months ago
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Based on #10

    Furtermore this should have a test added.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica
  • First commit to issue fork.
  • Merge request !37Resolve #3047358 "Entity validation" β†’ (Open) created by sickness29
  • Pipeline finished with Success
    7 months ago
    Total: 171s
    #293165
  • Pipeline finished with Success
    7 months ago
    Total: 178s
    #293168
  • πŸ‡ΊπŸ‡¦Ukraine sickness29

    Implemented the validate method that does the validation for the entity before submit to be able to set errors to bulk form fields. Previous patch just avoided errors and there was no validation errors shown to user.
    Also added a test case that checks node save with empty title as right now it results in WSOD.

    Hi @anybody,
    I don't see point in disabling entity validation.
    What the test you imagine for it would be? i.e. if enabled - we have proper validation errors on form and if disabled - WSOD?
    Right now I feel like it's important step in saving entity that is being missed, which is a bug that may result in WSOD in certain scenarios

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

    #14 worked for my case. We have a multi-value field that allows a maximum of 2 values. Previously, you could add as many values as you want -- the values would not save, nor would an error be thrown.

    After applying a patch from #14, user gets an error when >2 values are chosen.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    MR has a merge conflict that needs to be resolved.

    Furthermore, as this is a complex change, needs community review.

  • Pipeline finished with Failed
    6 months ago
    Total: 189s
    #325180
  • πŸ‡ΊπŸ‡¦Ukraine sickness29

    @anybody fixed merge conflict, please have a look.
    sure, I understand your concerns. anything I can do to help this process?

  • Status changed to Needs review 2 days ago
  • πŸ‡§πŸ‡ͺBelgium rp7

    @sickess29

    Previous patch just avoided errors and there was no validation errors shown to user.

    That's surprising. This patch has been in use for about a year, in a heavily used project of ours - we didn't get any complaints so far.

    We did spot an issue with it with in combination with a custom field widget we wrote. Adjusted the patch a little to make it more robust.

    Nevertheless, I'm all up for continuing with the work done in the MR - although I couldn't get it to work in my first tests. Will need more time to investigate.

Production build 0.71.5 2024