function photos_access_form_alter in Album Photos 7.3
Implements hook_form_alter().
File
- photos_access/
photos_access.module, line 81
Code
function photos_access_form_alter(&$form, &$form_state, $form_id) {
global $user;
if (isset($form['type']) && isset($form['#node'])) {
$node = $form['#node'];
$nid = isset($node->nid) ? $node->nid : 0;
if (variable_get('photos_access_' . $node->type, 0)) {
$form['privacy'] = array(
'#type' => 'fieldset',
'#title' => t('Privacy'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => -2,
'#tree' => TRUE,
);
// Access record(s) id.
$form['privacy']['access_id'] = array(
'#type' => 'value',
'#value' => isset($node->privacy['access_id']) ? $node->privacy['access_id'] : 0,
);
$form['privacy']['vid'] = array(
'#type' => 'value',
'#value' => isset($node->privacy['vid']) ? $node->privacy['vid'] : 0,
);
$form['privacy']['eid'] = array(
'#type' => 'value',
'#value' => isset($node->privacy['eid']) ? $node->privacy['eid'] : 0,
);
if ($nid && !isset($_SESSION['photos_access_' . $node->nid])) {
$_SESSION['photos_access_' . $node->nid] = isset($node->privacy) ? $node->privacy : '';
}
$old = $nid && isset($_SESSION['photos_access_' . $nid]) ? $_SESSION['photos_access_' . $nid] : array();
$form['privacy']['viewid'] = array(
'#type' => 'radios',
'#title' => t('Privacy'),
'#default_value' => isset($node->privacy['viewid']) ? $node->privacy['viewid'] : 0,
'#options' => array(
t('Open'),
t('Locked'),
t('Designated users'),
t('Password required'),
),
'#prefix' => '<div id="photos_access_privacy">',
'#suffix' => '</div>',
);
$form['privacy']['pass'] = array(
'#type' => 'password',
'#title' => t('Password'),
'#default_value' => isset($node->privacy['pass']) ? $node->privacy['pass'] : '',
'#prefix' => '<div id="photos_access_password">',
'#suffix' => '</div>',
);
$userhelp = t('Separated by commas. eg: username1,username2,username3.');
$form['privacy']['viewuser'] = array(
'#type' => 'textfield',
'#title' => t('Designated users'),
'#autocomplete_path' => 'photos-access/user/autocomplete/multiple',
'#default_value' => isset($node->privacy['viewuser']) && !is_array($node->privacy['viewuser']) ? $node->privacy['viewuser'] : NULL,
'#description' => t('Add people who will have access to view this node.') . ' ' . (isset($old['viewuser']) ? t('@help At present allow users:', array(
'@help' => $userhelp,
)) . ' ' : $userhelp),
'#prefix' => '<div id="photos_access_viewuser">',
'#suffix' => '</div>',
);
if (!empty($old['viewuser'])) {
foreach ($old['viewuser'] as $u) {
$form['privacy']['viewremove'][$u->uid] = array(
'#type' => 'checkbox',
'#default_value' => isset($node->viewremove[$u->uid]) ? $node->viewremove[$u->uid] : '',
'#title' => t('Delete: !name', array(
'!name' => $u->username,
)),
'#prefix' => '<div class="photos_access_remove">',
'#suffix' => '</div>',
);
}
}
$form['privacy']['updateuser'] = array(
'#type' => 'textfield',
'#title' => t('Add collaborators'),
'#autocomplete_path' => 'photos-access/user/autocomplete/multiple',
'#default_value' => isset($node->privacy['updateuser']) && !is_array($node->privacy['updateuser']) ? $node->privacy['updateuser'] : NULL,
'#description' => t('Add people who will have the authority to edit this node.') . ' ' . (isset($old['updateuser']) ? t('@help collaboration users list:', array(
'@help' => $userhelp,
)) . ' ' : $userhelp),
);
if (!empty($old['updateuser'])) {
foreach ($old['updateuser'] as $u) {
$form['privacy']['updateremove'][$u->uid] = array(
'#type' => 'checkbox',
'#default_value' => isset($node->updateremove[$u->uid]) ? $node->updateremove[$u->uid] : '',
'#title' => t('Delete: !name', array(
'!name' => $u->username,
)),
'#prefix' => '<div class="photos_access_updateremove">',
'#suffix' => '</div>',
);
}
}
}
}
}