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

Improve API error message on missing Selection option

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: InputQ
    • Priority: Medium
    • Resolution: Unresolved
    • Affects Version/s: 1.13.3, 5.4.12, 1.7.8, 2.2.2
    • Fix Version/s: None
    • Labels:
      None

      Description

      See https://jira.ez.no/browse/EZP-28258 for background information and steps to reproduce.

      When using the API to save/publish a Content Object that has ezselection Field Type with the selected option that no longer exists (because it was deleted from the Content Type definition) the following error is returned:
      [eZ\Publish\Core\Base\Exceptions\ContentFieldValidationException]
      Content fields did not validate

      This doesn't tell you which field failed, and why. It can be done by hardcoding in ContentFieldValidationException, but this is obviously not a viable solution for the product:

      diff --git a/eZ/Publish/Core/Base/Exceptions/ContentFieldValidationException.php b/eZ/Publish/Core/Base/Exceptions/ContentFieldValidationException.php
      index 913462637..f01bc370a 100644
      --- a/eZ/Publish/Core/Base/Exceptions/ContentFieldValidationException.php
      +++ b/eZ/Publish/Core/Base/Exceptions/ContentFieldValidationException.php
      @@ -38,7 +38,13 @@ class ContentFieldValidationException extends APIContentFieldValidationException
           public function __construct(array $errors)
           {
               $this->errors = $errors;
      -        parent::__construct('Content fields did not validate');
      +$str = '';
      +foreach($this->getFieldErrors() as $fieldError) {
      +    $str .= "\n" . str_replace('%index%',
      +                               $fieldError['eng-GB'][0]->getTranslatableMessage()->values['index'],
      +                               $fieldError['eng-GB'][0]->getTranslatableMessage()->message);
      +}
      +        parent::__construct('Content fields did not validate' . $str);
           }
      
           /**
      

      https://gist.github.com/glye/5cefe0e3036ebc09210262be123b5f31

      It seems a proper solution will require a BC break.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              gunnstein.lye@ez.no Gunnstein Lye
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: