It works.
i use a form to create a ressource with user id in tv and save the ressource id in the extend field of the user`
i call my snipet “CreateRessource” in a hook
[[!FormIt?
&hooks=`spam,email,redirect,CreateResource,FormItSaveForm
and there is my snippet :
<?php
/* variables initialisation */
$parent = 9;
$doc = $modx->getObject('modResource',array('id'=>$hook->getValue('resource_id')));
$userid = $modx->user->get('id');
/* Initialisation of future Ressource*/
if (empty($doc)){
$doc = $modx->newObject('modResource');
$doc->set('createdby', $userid);}else{$doc->set('editedby', $userid);
}
/* we set element who are not in the form*/
$doc->set('parent', $parent);
/*we make a loop on every fiel and get its value*/
$allFormFields = $hook->getValues();
foreach ($allFormFields as $field=>$value)
{
if ($field == 'projectname'){
$doc->set('pagetitle', $value);
}
if ($field == 'projectdescription'){
$doc->set('content', $value);
}
if ($field == 'emission'){
if ($value[0] == "oui"){ $doc->set('template', '13');}else{ $doc->set('template', '12');}
}
/*--------TV--------*/
if ($field == 'firstname'){
$firstname = $value;
}
if ($field == 'lastname'){
$lastname = $value;
}
if ($field == 'email'){
$email = $value;
}
if ($field == 'phone'){
$phone = $value;
}
if ($field == 'adresse'){
$adresse = $value;
}
if ($field == 'postcode'){
$zipcode = $value;
}
if ($field == 'town'){
$town = $value;
}
if ($field == 'projecturl'){
$url = $value;
}
/*if ($field !== 'spam' && $field !== 'resource_id' && $field !== 'template'){
$doc->set($field, $value);
}*/
}
/*we save the ressource one time to set the template and get the right tv*/
$doc->save();
/*we create the user extended field*/
$id = $doc->get('id');
$profile = $modx->user->getOne('Profile');
$extended = array();
$extended = $profile->get('extended');
$extended = ['RessourcesId' => $id];
$profile->set('extended', $extended);
$profile->save();
/*now we can set TV*/
$doc->setTVValue(30,$userid);
$doc->setTVValue( 7,$firstname);
$doc->setTVValue( 8,$lastname);
$doc->setTVValue( 6,$email);
$doc->setTVValue( 9,$phone);
$doc->setTVValue( 4,$adresse);
$doc->setTVValue( 12,$zipcode);
$doc->setTVValue( 10,$town);
$doc->setTVValue( 11,$url);
$doc->save();
return true;
and in a user page acceced by login i put a snippet to retreave information of the right ressource
<?php
/* we get user identification */
$user = $modx->user->get('id');
$modx->setPlaceholder('userID',$user);
/*we retreave ressource id stored in extended fiels and show it in a placeholder*/
$profile = $modx->user->getOne('Profile');
$extended = $profile->get('extended');
$RessourceID=$extended['RessourcesId'];
$modx->setPlaceholder('StartupID',$RessourceID);
$resourceObj = $modx->getObject('modResource', $RessourceID);
/* if we get one we show tv from the ressource id in placeholders*/
if ($resourceObj) {
$modx->setPlaceholder('StartupName', $resourceObj->get('pagetitle'));
$modx->setPlaceholder('StartupFirstName', $resourceObj->getTVValue('StartupFirstNameTV'));
$modx->setPlaceholder('StartupLastName', $resourceObj->getTVValue('StartupLastNameTV'));
$modx->setPlaceholder('StartupPhone', $resourceObj->getTVValue('StartupPhoneTV'));
$modx->setPlaceholder('StartupUrl', $resourceObj->getTVValue('StartupUrlTV'));
$modx->setPlaceholder('startupEmail', $resourceObj->getTVValue('StartupEmailTV'));
$modx->setPlaceholder('StartupAdress', $resourceObj->getTVValue('StartupAdressTV'));
$modx->setPlaceholder('StartupTown', $resourceObj->getTVValue('StartupTownTV'));
$modx->setPlaceholder('StartupZipcode', $resourceObj->getTVValue('StartupZipcodeTV'));
}