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

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
User avatar
rotezecke
Power Poster
Power Poster
Posts: 411
Joined: Fri Apr 18, 2008 9:34 pm
Location: Nimbin, Australia

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

Post 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.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3479
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

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

Post 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.
User avatar
rotezecke
Power Poster
Power Poster
Posts: 411
Joined: Fri Apr 18, 2008 9:34 pm
Location: Nimbin, Australia

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

Post 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 :)
Post Reply

Return to “Developers Discussion”