profile.inc in Patterns 5
File
components/profile.inc
View source
<?php
function profile_patterns($op, $id = null, &$data = null) {
switch ($op) {
case 'tags':
return array(
'profile',
);
break;
case 'actions':
return array(
'profile_field_form' => t('Create new profile field'),
'profile_field_delete' => t('Delete profile field'),
);
break;
case 'summary':
if ($id == 'profile_field_form') {
return t('Creating profile field %name', array(
'%name' => $data['title'],
));
}
else {
if ($id == 'profile_field_delete') {
return t('Deleting profile field %name', array(
'%name' => $data['name'],
));
}
}
break;
case 'prepare':
$fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE name = "%s"', $data['name']));
if ($data['delete'] && !$data['fid']) {
$data['fid'] = $fid;
}
else {
if (!$data['fid'] && $fid) {
$data['fid'] = $fid;
}
else {
if ($data['fid'] && !$fid) {
unset($data['fid']);
}
}
}
break;
case 'pre-validate':
if (!$data['name']) {
return t('<profile> actions require a <name> for the profile field.');
}
break;
case 'form_id':
if ($data['delete']) {
if (!$data['fid']) {
return;
}
return 'profile_field_delete';
}
else {
return 'profile_field_form';
}
break;
case 'build':
if ($id == 'profile_field_delete') {
$data['confirm'] = 1;
}
else {
if ($id == 'profile_field_form') {
if ($data['fid']) {
static $old_q;
$old_q = $_GET['q'];
$_GET['q'] = 'admin/user/profile/edit/' . $data['fid'];
}
}
}
return $data;
break;
case 'validate':
break;
case 'params':
if ($id == 'profile_field_form') {
if (!$data['type'] && !$data['fid']) {
return array(
'textfield',
);
}
else {
if (!$data['fid']) {
return $data['type'];
}
else {
return $data['fid'];
}
}
}
else {
if ($id == 'profile_field_delete') {
return $data['fid'];
}
}
break;
case 'cleanup':
static $old_q;
if ($old_q) {
$_GET['q'] = $old_q;
unset($old_q);
}
break;
case 'reverse':
if ($data['delete']) {
unset($data['delete']);
}
else {
$data['delete'] = true;
}
return $data;
break;
}
}