Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-20051

Setting an empty value to a required field won't trigger a ContentValidationException

    XMLWordPrintable

Details

    • Story
    • Resolution: Fixed
    • High
    • 5.1
    • None
    • Field types

    Description

      In the current situation, a ContentValidationException exception is thrown (https://github.com/ezsystems/ezp-next/blob/master/eZ/Publish/Core/Repository/ContentService.php#L542) when the field is marked as required and the field has not been set at all.
      However, setting it with empty content will not trigger it:

      $content->setField( "requiredTextLineField", "" );
      

      The method isEmptyValue() (https://github.com/ezsystems/ezp-next/blob/master/eZ/Publish/Core/FieldType/FieldType.php#L258) is used to test emptyness in a very generic way and is until now, never overridden:

      public function isEmptyValue( $value )
      {
          return ( $value == $this->getEmptyValue() );
      }
      

      Some field types' getEmptyValue() returns null, some returns a Value object.

      The values used for emptyness has been summarized in a document: https://docs.google.com/a/schlitt.info/spreadsheet/ccc?key=0ApxQ-KCWjCMBdFItWlRuQ2ptZFNsNFFOb3VHZ1BXR2c but it looks out of sync with the ones returning a Value object.

      Approach 1: Shouldn't all getEmptyValue() return a Value object? Which can be used by isEmptyValue() to compare with the == operator for most Field Types? And more complex ones would override the isEmptyValue() (XmlText for example).

      Approach 2: Should the current return values of getEmptyValue() be preserved and isEmptyValue() surround calls to getEmptyValue() with acceptValue():

      public function isEmptyValue( $value )
      {
          return ( $value == $this->acceptValue( $this->getEmptyValue() ) );
      }
      

      Approach 3: Nor getEmptyValue() nor isEmptyValue() should be changed, isEmptyValue() should be implemented for most field types.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              patrick.allaert-obsolete@ez.no Patrick Allaert (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Time Spent - 3 days, 1 hour, 45 minutes Remaining Estimate - 30 minutes
                  30m
                  Logged:
                  Time Spent - 3 days, 1 hour, 45 minutes Remaining Estimate - 30 minutes
                  3d 1h 45m