Ibexa DXP Discussions

Community discussion forum for developers working with Ibexa DXP

Ezobjectrelationlist return hidden ans deleted objects on front

I have au ezobjectrelationlist with a hidden content and a content in the trash.

But they’re both going up front.

{{ dump(site_settings.getFieldValue('header_menu').destinationContentIds) }}
{{ dump(ez_field_value(site_settings, 'header_menu').destinationContentIds) }}
{{ ez_render_field(site_settings, 'header_menu') }}

I use this relationship to administer the main menu of the site.

view/pagelayout.html.twig

{# Menu principal administrable #}
    <nav id="header_menu">
        <ul>
            {% if site_settings %}
                {% for contentId in site_settings.getFieldValue('header_menu').destinationContentIds %}
                    {{ render(controller("ez_content:viewAction", {"contentId": contentId, "viewType": "menu_item"})) }}
                {% endfor %}
            {% endif %}
        </ul>
    </nav>

In the template of my menu_item view I can check if the object is well published.

view/menu_item/link.html.twig

{% if content.versionInfo.contentInfo.published %}
<li>
   {# ... #}
</li>
{% endif %}

But how do we know if it’s hidden?

Then of course. It’s the Location that’s hidden. And the ezobjectrelationrelist refers to Content. But in the previous versions it seems to me that the hidden objects (no visible nodes); were invisible in front.

I was able to get around my problem by going through a controler that checked the validity of the items before sending them to the template.

But it’s a little crazy

view/pagelayout.html.twig

{# Menu principal administrable #}
    <nav id="header_menu">
        <ul>
            {{ render_esi(controller("MyBundle:Pagelayout:headerMenu")) }}
        </ul>
    </nav>

PagelayoutControler

    public function headerMenuAction()
    {
        $s = $this->container->get('my_project.service.pagelayout');
        $siteSettings = $edbService->getSiteSettings();
        $v = $siteSettings->getFieldValue('header_menu');

        $items = [];

        foreach($v->destinationContentIds as $destinationContentId) {
            $c = $this->getRepository()->getContentService()->loadContent($destinationContentId);
            if ($c && $c->contentInfo && $c->contentInfo->mainLocationId) {
                $l = $this->getRepository()->getLocationService()->loadLocation($c->contentInfo->mainLocationId);
                if ($l && !$l->invisible) {
                    $items[] = $destinationContentId;
                }
            }
        }

        return  $this->render('MyBundle:parts:header_menu_items.html.twig', array(
            'items' => $items,
        ));
    }

header_menu_items.html.twig

    {% for contentId in items %}
        {{ render(controller("ez_content:viewAction", {"contentId": contentId, "viewType": "menu_item"})) }}
    {% endfor %}

I have the same problem: when I try to display my related objects in front, the ones that are in the trash are still listed, and in the template for embedded display I have access to their content, but it is impossible to link to them (the usual {{ path(‘ez_urlalias’, { ‘contentId’: content.id }) }} generates an exception : “Cannot generate an UrlAlias route for content without main location.”) and the page returns a 500 Internal Server error.

Is this the new native behaviour? If yes, what would be a workaround to avoid this exception (except everytime checking in the ContentInfo for a main location which seems tedious at best)? I think that in this state, this is a problem that needs one.

Could you please share with me the complete solution on this one?

Regards, Atle

Salut @Nesrene,

I’m not sure what you’re missing…

use eZ\Bundle\EzPublishCoreBundle\Controller;

class PagelayoutControler extends Controller
{
    public function headerMenuAction()
    {
        // $siteSettings is a Content with a Content Relations Field named 'header_menu'.
        $v = $siteSettings->getFieldValue('header_menu');

        $items = [];

        foreach($v->destinationContentIds as $destinationContentId) {
            $c = $this->getRepository()->getContentService()->loadContent($destinationContentId);
            if ($c && $c->contentInfo && $c->contentInfo->mainLocationId) {
                $l = $this->getRepository()->getLocationService()->loadLocation($c->contentInfo->mainLocationId);
                if ($l && !$l->invisible) {
                    $items[] = $destinationContentId;
                }
            }
        }

        return  $this->render('MyBundle:parts:header_menu_items.html.twig', array(
            'items' => $items,
        ));
    }

Hei, Remy and thanks for your reply.

I am looking for your solution as a whole. I am new to ezplatform, and somewhat lost in this. Really misses examples in the documentation.

Regadrs, Atle.