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

Can't publish/save content with missing Selection option

    XMLWordPrintable

Details

    Description

      When trying 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 shown in the eZ Platform UI:

      Option with index -1 does not exist in the field definition.

      Also, you cannot remove this option from the Selection field (the "x" icon is not clickable).
      This error also manifests itself when using Public PHP API.
      eZ Publish 5.4 is affected only when using Public PHP API (and not the legacy admin panel).
      Full response with the error:

      {
          "ErrorMessage": {
              "_media-type": "application\/vnd.ez.api.ErrorMessage+json",
              "errorCode": 400,
              "errorMessage": "Bad Request",
              "errorDescription": "Content fields did not validate",
              "errorDetails": {
                  "fields": [
                      {
                          "_fieldTypeId": 182,
                          "errors": [
                              {
                                  "type": "selection",
                                  "message": "Option with index -1 does not exist in the field definition."
                              }
                          ]
                      }
                  ]
              },
              "trace": "#0 xxx\\vendor\\ezsystems\\platform-ui-bundle\\Controller\\Rest\\ContentController.php(92): eZ\\Publish\\Core\\REST\\Server\\Controller\\Content->updateVersion('54', '5', Object(Symfony\\Component\\HttpFoundation\\Request))\n#1 [internal function]: EzSystems\\PlatformUIBundle\\Controller\\Rest\\ContentController->updateVersion('54', '5', Object(Symfony\\Component\\HttpFoundation\\Request))\n#2 xxx\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\HttpKernel\\HttpKernel.php(137): call_user_func_array(Array, Array)\n#3 xxx\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\HttpKernel\\HttpKernel.php(57): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw(Object(Symfony\\Component\\HttpFoundation\\Request), 1)\n#4 xxx\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\HttpKernel\\DependencyInjection\\ContainerAwareHttpKernel.php(67): Symfony\\Component\\HttpKernel\\HttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#5 xxx\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\HttpKernel\\Kernel.php(183): Symfony\\Component\\HttpKernel\\DependencyInjection\\ContainerAwareHttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#6 xxx\\web\\app.php(67): Symfony\\Component\\HttpKernel\\Kernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request))\n#7 {main}",
              "file": "xxx\\vendor\\ezsystems\\ezpublish-kernel\\eZ\\Publish\\Core\\REST\\Server\\Controller\\Content.php",
              "line": 494
          }
      }
      

      Steps to reproduce for eZ Platform

      1. Create new eZ Platform installation.
      2. Create a new Content Type named "Selection Content Type" with two Content Fields:
        • ezstring named "Title".
        • ezselection named "Selection" and two options "1st option" and "2nd option".
      3. Create new Content Object with "Selection Content Type" Content Type. In the "Title" field type "Selection Test" and in the "Selection" field select "2nd option".
      4. Go to the "Selection Content Type" Content Type definition and edit it. Remove the "2nd option" option from the "Selection" Field.
      5. Navigate back to "Selection Test" Content Object and edit it. Try to publish the draft immediately. You will notice the error described above.

      Steps to reproduce for eZ Publish

      1. Create new eZ Publish installation.
      2. Create a new Content Type named "Selection Content Type" with two Content Fields:
        • ezstring named "Title".
        • ezselection named "Selection" and two options "1st option" and "2nd option".
      3. Create new Content Object with "Selection Content Type" Content Type. In the "Title" field type "Selection Test" and in the "Selection" field select "2nd option".
      4. Go to the "Selection Content Type" Content Type definition and edit it. Remove the "2nd option" option from the "Selection" Field.
      5. Add the following command to your App Bundle:
        <?php
        
        namespace AppBundle\Command;
        
        use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
        use Symfony\Component\Console\Input\InputInterface;
        use Symfony\Component\Console\Output\OutputInterface;
        
        class TestCommand extends ContainerAwareCommand
        {
            protected function configure()
            {
                $this
                    ->setName('app:test_command');
            }
        
            protected function execute(InputInterface $input, OutputInterface $output)
            {
                $repository = $this->getContainer()->get('ezpublish.api.repository');
        
                $userService = $repository->getUserService();
                $user = $userService->loadUserByLogin('admin');
                $repository->setCurrentUser($user);
        
                $contentService = $repository->getContentService();
                $content = $contentService->loadContent(64);
                $contentUpdateStruct = $contentService->newContentUpdateStruct();
                $contentUpdateStruct->setField('title', 'Test Selection 2');
        
                $contentDraft = $contentService->createContentDraft($content->contentInfo);
        
                $contentDraft = $contentService->updateContent($contentDraft->versionInfo, $contentUpdateStruct);
                $content = $contentService->publishVersion($contentDraft->versionInfo);
            }
        }
        

        Remember to change Content's id (64) to the Content id of "Selection Test" Content Object in your installation.

      6. Run the command by entering the following in the console:
        php ezpublish/console app:test_command
        
      7. You will be presented with the following error:
          [eZ\Publish\Core\Base\Exceptions\ContentFieldValidationException]
          Content fields did not validate
        

      Attachments

        Activity

          People

            Unassigned Unassigned
            jacek.foremski-obsolete@ez.no Jacek Foremski (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 days, 6 hours, 30 minutes
                4d 6h 30m