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

Cannot properly preview drafts when enriching ViewController with a custom controller

    XMLWordPrintable

Details

    Description

      When using a custom controller alongside a ViewController for displaying a content type, it is not possible to use "Preview" feature for drafts correctly.
      When using the custom controller, the developer should forward the request to the original ViewController. He can do that in two ways - using viewLocation or viewContent functions. The example in the documentation uses viewLocation function, however using it with drafts is not supported as they do not have a location, which leads to errors (see https://jira.ez.no/browse/EZP-27123?focusedCommentId=213938&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-213938).
      The second option is to use viewContent function. However, this function always loads the last published version of a Content Object instead of the version that is being previewed.

      Steps to reproduce (using viewContent)

      1. Create fresh eZ Publish 5.4 installation.
      2. In the "src" directory of your project, create new AppBundle directory with new bundle. There, create the following files (or use the attached files):
        • AppBundle/Controller/DefaultController with the following code:
          <?php
          
          namespace AppBundle\Controller;
          
          use eZ\Bundle\EzPublishCoreBundle\Controller;
          use eZ\Publish\API\Repository\Values\Content\Location;
          
          class DefaultController extends Controller
          {
              public function articleViewEnhancedAction(
                  Location $location,
                  $viewType,
                  $layout = false,
                  array $params = array()
              ) {
                  if (isset($params['isPreview'])) {
                      $response = $this->get('ez_content')->viewContent(
                          $location->contentInfo->id,
                          $viewType,
                          $layout,
                          $params
                      );
                  } else {
                      $response = $this->get('ez_content')->viewLocation($location->id, $viewType, $layout, $params);
                  }
          
                  return $response;
              }
          }
          
          
        • AppBundle/Resources/views/full/article.html.twig with the following code:
          <h1>{{ ez_render_field( content, 'title' ) }}</h1>
          
      3. Register AppBundle by adding the following line to the bundles array in ezpublish/EzPublishKernel.php file:
                    new AppBundle\AppBundle(),
        
      4. Paste the following configuration to the ezpublish/config/ezpublish.yml file:
        ezpublish:
            system:
                ezdemo_site_clean_group:
                    location_view:
                        full:
                            article:
                                controller: AppBundle:Default:articleViewEnhanced
                                template: AppBundle:full:article.html.twig
                                match:
                                    Identifier\ContentType: [article]
                    content_view:
                        full:
                            article:
                                template: AppBundle:full:article.html.twig
                                match:
                                    Identifier\ContentType: [article]
        
      5. In the legacy admin, go to "Content structure". Under "Home", create a new Article Content Object titled "Test" and publish it.
      6. Edit the "Test" Article. Change its title to "Test2" and save the draft without publishing.
      7. Under "Current draft" click "Preview" button.
      8. On the top, the correct Article draft name will be shown ("Test2"). However, in the preview window beneath it there will be the old title shown ("Test").

      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: