eZ Community » Forums » eZ Publish 5 Platform » eZ 53 - eZ flow and hidden content
expandshrink

eZ 53 - eZ flow and hidden content

eZ 53 - eZ flow and hidden content

Friday 08 August 2014 12:54:41 pm - 2 replies

I have an issue with eZ Flow and hidden content. 

If an editor assigns a content to an eZ Flow block and it is hidden later on  an exception is thrown but not catched.  The exception is shown on the frontend and the eZ Flow page "is gone". 

The excepted behavior will be just to ignore the hidden content. 

Does anyone has a solution for this? 

Monday 11 August 2014 5:11:13 pm

Hi, i would try to present you a solution based on an example provided in the Ez Demo Bundle, so in order to follow with me, get a fresh installation of ez publish (version 5.3 (2014.05)) in your computer

connect to the admin interface, then select the location (node) Getting Started, the type of the content corresponding to this location is Landing Page, which means that it is using ez flow, here we will focus on the block of type Highlighted Item

you may need to read the documentation about ez flow in order to understand a little more how it works, espacially here how a zone, block and block item are rendered, check for example the Page fieldtype doc (https://doc.ez.no/display/EZP/The+Page+FieldType ) the ez flow extension doc (https://doc.ez.no/Extensions/eZ-P...Configuring-the-eZ-Flow-block-system ), you may need to invistigate through the ez demo bundle source code while reading the docs in order to grasp something, also note that ez flow is a legacy stack extension and used in the new version which complicates the task too

the problem that you have is apparently coming from the fact that the twig template that is responsible for rendering your block is using the viewLocation method of ez publish ViewController to render the block items, this is the case for the block mentioned above, the block is of type Highlighted Item, its rendering template is located in ezp-root-dir/vendor/ezsystems/demobundle/EzSystems/DemoBundle/Resources/views/block/highlighted_item.html.twig, here is its content

{% if valid_items is not empty %}
<div class="block-type-highlighted-item block-view-{{ block.view }}">
    {{ render(
       controller(
           "ez_content:viewLocation",
           {
               "locationId": valid_items[0].locationId,
               "viewType": "block_item_highlighted",
               "params": {"image_alias": "contentgrid"}
           }
       )
   ) }}
</div>
{% endif %}

it is the code inside the div that calls the viewLocation method, i don't know every detail of this method (you can inspect its code by locating it inside the ViewController's code here https://github.com/ezsystems/ezpublish-kernel/blob/master/eZ/Publish/Core/MVC/Symfony/Controller/Content/ViewController.php ) but apparently it would throw an exception if the given location is invisible, so a solution would be to not call the viewController for invisible locations, i didn't find a way to do it directly inside the template (using the locationId or any other valid_items[i] attribute) so i would call a custom controller, the above code would become

{% if valid_items is not empty %}
<div class="block-type-highlighted-item block-view-{{ block.view }}">
    {{ render(
       controller(
           "YourBundle:EzFlow:blockItem",
           {
               "locationId": valid_items[0].locationId,
               "viewType": "block_item_highlighted",
               "params": {"image_alias": "contentgrid"}
           }
       )
   ) }}
</div>
{% endif %}

and the controller code would be

namespace YourBundle\Controller;
 
use eZ\Bundle\EzPublishCoreBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
 
class EzFlowController extends Controller
{
    public function BlockItemAction( $locationId, $viewType, $layout = false, array $params )
    {
        $locationService = $this->getRepository()->getLocationService();
        $location = $locationService->loadLocation( $locationId );
        if ($location->invisible) {
            return new Response();
        } else {
            return $this->get( 'ez_content' )->viewLocation( $locationId, $viewType, $layout, $params );
        }
    }
}

you may ask me some questions if you don't understand some points, note that my solution add an overhead into the performances so you may stick to the default (exception throw) or cache the response somehow if you comfortable with symfony 2/ez publish 5 cache

Modified on Monday 11 August 2014 5:30:12 pm by pr pr

Monday 18 August 2014 8:50:06 pm

Hi,

thank you very much for your detailed solution! 

Ialso had a simliar idea.

The good thing is: 

Meanwhile  we found out that this problem just occurs in the dev mode. In "prod" mode eZ behaves as expected (tested in Version 5.3). 

So from my point of view that´s ok (not perfect since in dev mode the system behaves different). 

 

Cheers Frank

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from