Creating Collections view returns 500 error

I just installed the Collections extra and while trying to create a new view, a click on the save button does nothing. The console shows a 500 error for /assets/components/collections/connector.php.

Apache error log shows:

[php:error] [pid 31148] [client 127.0.0.1:64033] PHP Fatal error:  Uncaught TypeError: explode(): Argument #2 ($string) must be of type string, array given in /var/www/html/project/core/components/collections/model/collections/collections.class.php:131

Stack trace:
#0 /var/www/html/project/core/components/collections/model/collections/collections.class.php(131): explode()
#1 /var/www/html/project/core/components/collections/processors/mgr/template/create.class.php(98): Collections->explodeAndClean()
#2 /var/www/html/project/core/model/modx/modprocessor.class.php(647): CollectionsTemplateCreateProcessor->beforeSet()
#3 /var/www/html/project/core/model/modx/modprocessor.class.php(185): modObjectCreateProcessor->process()
#4 /var/www/html/project/core/model/modx/modx.class.php(1770): modProcessor->run()
#5 /var/www/html/project/core/model/modx/modconnectorresponse.class.php(144): modX->runProcessor()
#6 /var/www/html/project/core/model/modx/modconnectorrequest.class.php(86): modConnectorResponse->outputContent()
#7 /var/www/html/project/core/model/modx/modconnectorrequest.class.php(73): modConnectorRequest->prepareResponse()
#8 /var/www/html/project/assets/components/collections/connector.php(23): modConnectorRequest->handleRequest()
#9 {main}

thrown in /var/www/html/project/core/components/collections/model/collections/collections.class.php on line 131, referer: http://localhost/manager/?a=template/create&namespace=collections

I first thought of file/folder permission issues, but after running chmod 755 on everything within the /assets folder the issue still persists.

Interestingly enough while editing the default “Blog” view, hitting save checks out fine with a 200 to the connector.php.

Any ideas?

There seems to be a bug in the mgr/template/create processor.

The value from the field “Default for templates” (templates) is an array but the code treats it like a string.


As a temporary fix you could try adding these lines between line 97 and 98.

if (is_array($templates)){
	$templates = implode(',', $templates);
}

(But it seems that you have to click “update view” and set that field again afterwards to make it work.)


Maybe it’s easier to just duplicate the default view (and adjust it) instead of creating a new one.

Thank you very much, your fix worked!

Do you know why this is (suddenly) happening? I’ve never had this issue before using Collections…

Do you use PHP 8?
The code is also wrong on PHP 7.4, but I think it doesn’t throw a fatal error.

1 Like

Yes, that must be it then. I think all other sites so far where I used Collections are still on 7.4. Thanks for clarifying!

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.