Page 1 of 1

$content_obj->ValidateData() returns error when it should not

Posted: Fri May 14, 2021 11:15 pm
by rotezecke
my plugin that creates pages on the fly is coming along but it has at least one flaw. The code to create the page is pretty much a clone from the admin page. However, I am setting the alias

Code: Select all

...
$content_obj->SetAlias($newfieldname);
$newfieldname is a MAMS property, just been tested whether or not it is a new property, or existing one. That works fine. And it is highly unlikely that the MAMS property will ever be an existing page alias, however, I'd prefer to test it at this point (but don't know how). I cannot use this one:

Code: Select all

$error = $content_obj->ValidateData();
as it always returns an error:
[0] => An error occurred parsing content blocks (look for an invalid template, or duplicated content blocks)
[1] => No default content block was detected in this template. Please ensure that you have a {content} tag in the page template.
So i guess I have two questions:
1) can I test whether or not a page alias already exists, and
2) why would $content_obj->ValidateData(); report the error, when $content_obj->Save(); works just fine?
The pages that I end up creating are exactly as I want them to be, short of the missing error/alias check. Thank you.

Re: $content_obj->ValidateData() returns error when it should not

Posted: Mon May 17, 2021 8:43 am
by velden
Think you found this yourself already but seems to me that method get_content_blocks on line 317 in lib\classes\contenttypes\Content.inc.php fails to load the content blocks.

Something to debug.

Re: $content_obj->ValidateData() returns error when it should not

Posted: Thu May 20, 2021 11:41 pm
by rotezecke
Thanks velden.
my debugging did not go so well, but resulted in a funny twist. while trying to figure out why the get_content_blocks would fail, I discovered ! CheckAliasError();

Code: Select all

$contentops = cmsms()->GetContentOperations();
if(! $contentops->CheckAliasError($newfieldname))
{
 ...create page
}
also documented here: https://apidoc.cmsmadesimple.org/classe ... tions.html
this does not answer my question 2), but since question 1) is sorted, 2) is no longer a problem :)