Is there a nice tidy way to set the formit hooks in a class?
I have a snippet [GetArtistData]:
/**
*
* snippet.GetArtistData.php
*
* Created using: JetBrains PhpStorm
* User: Sean Kimball [email protected]
* BigBlock Studios http://www.bigblockstudios.ca
* http://github.com/BigBlockStudios
* Date: 29/04/12, 6:36 PM
*
*/
$classfile = dirname($modx->getOption('core_path')).'/core/components/extdata/controllers/extdata.class.php';
if (file_exists($classfile)) {
$output = include_once $classfile;
} else {
$modx->setLogTarget('ECHO');
$modx->log(modX::LOG_LEVEL_ERROR,'class not found at: '.$file);
}
$scriptproperties = array('query'=>'false',);
if(class_exists('ExtraData') != true)
{
$ExtraData = new ExtData($modx,$scriptproperties);
}
$output = $ExtraData->getData($scriptproperties);
$hook->setValues(array(
'title'=>$output['title'],
'bio'=>$output['bio'],
'banner'=>$output['banner'],
'manager'=>$output['manager'],
'FaceBook'=>$output['FaceBook'],
'YouTube'=>$output['YouTube'],
'Twitter'=>$output['Twitter'],
'MySpace'=>$output['MySpace'],
));
return true;
calling this function within the ExtData class:
// get data from the extra data tables...
public function getData($scriptproperties){
$output = '';
$uid = $this->modx->getLoginUserID();
// look for existing artist record
$artistId = $uid;
$records = $this->modx->getObject ('ArtistAttributes', array('userkey'=>$artistId));
$social = json_decode($records->get('social'),true);
$output = array(
'userkey'=>$records->get('userkey'),
'title'=>$records->get('title'),
'banner'=>$records->get('banner'),
'bio'=>$records->get('bio'),
'manager'=>$records->get('manager'),
'social'=>$social,
'FaceBook'=>$social['FaceBook'],
'Twitter'=>$social['Twitter'],
'YouTube'=>$social['YouTube'],
'MySpace'=>$social['MySpace'],
);
return $output;
}
seems to me like I am overdoing it here, is there a nice tidy way to return the output array as 'hooks' to formit?
Also, slightly related, this is used as a prehook to populate the form, and as a hook to repopulate the form after submission, it works perfect when the page is visited initially, but after the form is submitted the form will remain blank after the page refreshes.... I am placing it after the update hook & the update hook always returns true... thoughts?
[[!FormIt?
&preHooks=`GetArtistData`
&hooks=`UpdateArtist,GetArtistData`
&successMessage=`Updated!`
&validate=`title:required, bio:required`
&segment=`attributes`
]]