What event is your plugin connected to? Make sure it's not connected to more than one.
No sure what's wrong. Possibly getTVValue() is returning NULL in some cases and saving NULL in the content field is the issue. Let's try it a different way:
$parent = (int) $resource->get('parent');
if ($parent == 22) {
$v = $resource->getTVValue('AwardItem_blurb');
$v = empty($v) ? ' ' : $v;
if ($v) {
$resource->setContent($v);
$resource->save();
}
}
return '';
[ed. note: BobRay last edited this post 11 years, 6 months ago.]
Thanks Bob - still getting Server 500 errors in Firebug on save of a resource with the plugin enabled...
Again, nothing in the MODx error log though - just never ending save loop...
Not sure if this is a local issue to me or the code is still not right? Have you had it working your end?
[ed. note: dubbs last edited this post 11 years, 6 months ago.]
Sorry, typo in the code.
Line 5 should be:
$v = empty($v) ? ' ' : $v;
(fixed above)
That looks fine. If there are going to be a bunch of them, I would do it this way:
$parent = (int) $resource->get('parent');
$resourceTvs = array(
22 => 'AwardItem_blurb',
30 => 'AnotherTV_blurb',
);
if (isset($resourceTvs[$parent])) {
$v = $resource->getTVValue($resourceTvs[$parent]);
$v = empty($v) ? ' ' : $v;
if ($v) {
$resource->setContent($v);
$resource->save();
}
}
return '';
It avoids duplicating the code, it will be faster, and you only have to change the array to add more. It won't work, though, if there's more than one TV involved for a resource.
[ed. note: BobRay last edited this post 11 years, 6 months ago.]
Glad I could help.