$doc = $modx->getObject('modResource',array('id'=>$hook->getValue('resource_id')));
<input type="hidden" name="resource_id" value="[[*id]]" />
Это обновление будет происходить в будущем?
И почему для него нельзя задействовать пакеты, чтобы обновил все до новых версий в управлении пакетами — и радуешься?
Например: РЕСУРС ОТЕЦ Ресурс пользователя 1 Ресурс пользователя 1 Ресурс пользователя 2 Ресурс пользователя 2
[[!FormIt? &hooks=`formit2resource,redirect` &redirectTo=`[[*id]]` &template=`15` ]]
<form id="add" action="[[~[[*id]]]]" method="post"> <input type="hidden" name="resource_id" value="[[*id]]" /> <input type="hidden" name="parent" id="parent" value="[[*id]]" /> <input type="hidden" name="published" id="published" value="1" /> <input type="hidden" name="hidemenu" id="hidemenu" value="1" /> <input type="hidden" name="cacheable" id="cacheable" value="0" /> Название: <input type="text" name="pagetitle" id="pagetitle" class="form-control" value="[[+fi.pagetitle]]" /> Описание: textarea id="content" name="content" class="form-control" style="height:150px;" <input type="submit" name="submit" style="margin-top:20px;" class="btn btn-yellow" value="Добавить" /> </form>
<?php $doc = $modx->getObject('modResource',array('id'=>$hook->getValue('resource_id'))); if (empty($doc)){ $doc = $modx->newObject('modResource'); $doc->set('createdby', $modx->user->get('id')); } else{ $doc->set('editedby', $modx->user->get('id')); } $allFormFields = $hook->getValues(); foreach ($allFormFields as $field=>$value) { if ($field !== 'spam' && $field !== 'resource_id'){ $doc->set($field, $value); } } $alias = $doc->cleanAlias($fields['pagetitle']); if($modx->getCount(modResource, array('alias'=>$alias))!= 0) { $count = 1; $newAlias = $alias; while($modx->getCount(modResource, array('alias'=>$newAlias))!= 0) { $newAlias = $alias; $newAlias .= '-' . $count; $count++; } $alias = $newAlias; } $doc->set('alias',$alias); $doc->set('template', $template); $doc->save(); foreach ($allFormFields as $field=>$value) { if (!empty($value) && $tv = $modx->getObject('modTemplateVar', array ('name'=>$field))) { /* handles checkboxes & multiple selects elements */ if (is_array($value)) { $featureInsert = array(); while (list($featureValue, $featureItem) = each($value)) { $featureInsert[count($featureInsert)] = $featureItem; } $value = implode('||',$featureInsert); } $tv->setValue($doc->get('id'), $value); $tv->save(); } } $modx->cacheManager->refresh(); return true;