eZ Platform Discussions

An exception has been thrown during the rendering of a template ("Argument '$targets' is invalid: Must contain objects of type: Location or LocationCreateStruct")


#1

Bonjour à tous.

I have a strange error (like many of the problems) that led me to a strange piece of code (that’s more rare…)

My contributor (so not an admin) creates an article but instead of publishing he just saves it.
He has the error :

An exception has been thrown during the rendering of a template (“Argument ‘$targets’ is invalid: Must contain objects of type: Location or LocationCreateStruct”).

The error is generated here.

ParentContentTypeLimitationType::evaluate(..., $targets)

And by adding a little bit of debugging I see that $targets has a strange value.

dump($targets); // array:1 [  0 => []]

The function is called here:

ConfigureMenuListener::canContentBePublished()
vendor/ezsystems/date-based-publisher/lib/Core/Menu/ConfigureMenuListener.php

dump($options);
array:5 [▼
  "content" => Content {#4613 ▶}
  "content_type" => ContentType {#4954 ▶}
  "rental" => null
  "parent_location" => Location {#5258 ▶}
  "language" => Language {#3163 ▶}
]

So if we do that:

$locationCreateStruct = array_key_exists('content_create_struct', $options) ? $options['content_create_struct']->getLocationStructs()[0] : [];
/** @var \eZ\Publish\API\Repository\Values\Content\Location|[] $location */
$location = $options['rental']?? [];
$target = !empty($locationCreateStruct) ? $locationCreateStruct : $location;

$target=[];

And it is used like that [$target] in the following.


To get around the problem, I did this:

$targer_array = $target? [$target]: [];

CanCreateContent = $this->permissionResolver->canUser(
                "content",
                "create",
                $content,
                $targer_array
            );

But now I’m modifying a vendor…


I’m not sure what I should do.
Is it a legal issue?


#2

Hi Remy!

The issue you’re describing seems very similar to: https://jira.ez.no/browse/EZEE-2702

Which has been fixed in 2.4.2 - which version are you using? If it’s an earlier release - is it possible for you to update and confirm that it solves your issue?


#3

Ha that’s cool. I think I’m in 2.4.0.