function avatar_selection_edit_form in Avatar Selection 6
Same name and namespace in other branches
- 5.2 avatar_selection.module \avatar_selection_edit_form()
- 5 avatar_selection.module \avatar_selection_edit_form()
- 7 avatar_selection.admin.inc \avatar_selection_edit_form()
Create the form structure for listing the avatars and managing them in the 'Manage Avatars' tab under the Avatar Selection administration page.
Parameters
$form_state: General variable, used to control the processing of the form.
Return value
Return the structure of the form.
2 string references to 'avatar_selection_edit_form'
- avatar_selection_roles_page in ./
avatar_selection.admin.inc - avatar_selection_settings_page in ./
avatar_selection.admin.inc - Select which form will be shown to the user, according to the permissions.
File
- ./
avatar_selection.admin.inc, line 348 - Administrative page callbacks for the avatar_selection module.
Code
function avatar_selection_edit_form($form_state) {
// We need the pager global variables.
global $_GET;
$form = array();
if (!variable_get('user_pictures', 0)) {
drupal_set_message(t('User Pictures option is disabled. You will need to enable this option before you can use the Avatar Selection module. You may configure this setting on the <a href="@url">User settings</a> page.', array(
'@url' => url('admin/user/settings'),
)));
}
drupal_add_css(drupal_get_path('module', 'avatar_selection') . '/avatar_selection.css');
$set_type = arg(4);
$set_id = arg(5);
// We find out the current page number.
$page = 0;
if (isset($_GET['page']) && is_numeric($_GET['page'])) {
$page = $_GET['page'];
}
$avatars_per_page = variable_get('avatar_selection_avatar_per_page', 30);
$selects = _avatar_selection_image_list('', $set_type, $set_id, $page * $avatars_per_page, $avatars_per_page);
if (!count($selects['avatars'])) {
drupal_set_message(t('There are no avatars configured.'));
}
else {
if (!isset($form_state['values'])) {
$step = 'list';
}
else {
$step = 'edit';
}
$form['step'] = array(
'#type' => 'value',
'#value' => $step,
);
if ($step == 'list') {
if ($set_type == 'role') {
$sets = avatar_selection_handler_filter_role();
}
elseif ($set_type == 'og') {
$sets = og_all_groups_options();
}
drupal_set_title(t('Manage Avatars - %name', array(
'%name' => $sets[$set_id],
)));
drupal_add_js(drupal_get_path('module', 'avatar_selection') . '/js/avatar_selection_pager.js', 'module', 'header');
$js_file = drupal_get_path('module', 'avatar_selection') . '/js/avatar_selection.js';
$form['select_avatar'] = array(
'#type' => 'radios',
'#title' => t('Select an avatar to edit'),
'#options' => $selects['avatars'],
'#required' => TRUE,
'#attributes' => array(
'class' => 'user_avatar_select',
),
'#suffix' => theme('avatar_selection_pager', 'form#avatar-selection-edit-form', 'div.user_avatar_select', $selects['total'], $avatars_per_page, '/' . $js_file),
);
$form['search'] = array(
'#type' => 'submit',
'#value' => t('Edit'),
'#submit' => array(
'avatar_selection_edit_list_form_submit',
),
);
drupal_add_js($js_file, 'module', 'header');
}
elseif ($step == 'edit') {
drupal_set_title(t('Manage Avatars'));
$form['#redirect'] = array(
'admin/settings/avatar_selection/edit',
);
$roles = avatar_selection_handler_filter_role();
$aid = 0;
$avs_access = $og_access = array();
$weight = 0;
$name = '';
$result = db_query("SELECT avs.aid, avatar, name, weight, rid, ogid FROM {avatar_selection} avs LEFT JOIN {avatar_selection_roles} avsr ON avs.aid = avsr.aid LEFT JOIN {avatar_selection_og} avso ON avs.aid = avso.aid WHERE avatar = '%s' ORDER BY weight, name, avatar", $form_state['values']['select_avatar']);
while ($avatar = db_fetch_object($result)) {
$aid = $avatar->aid;
$name = $avatar->name;
$weight = $avatar->weight;
if ($avatar->rid) {
array_push($avs_access, $avatar->rid);
}
if ($avatar->ogid) {
array_push($og_access, $avatar->ogid);
}
}
$image_path = file_create_path('avatar_selection');
$selected_avatar = $form_state['values']['select_avatar'];
$image = theme('image', $image_path . '/' . $selected_avatar);
$form['avatar_image'] = array(
'#value' => $image,
);
$form['aid'] = array(
'#type' => 'value',
'#value' => $aid,
);
$form['select_avatar'] = array(
'#type' => 'value',
'#value' => $form_state['values']['select_avatar'],
);
$form['avatar_name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#description' => t("Image name or title which will be displayed when hovering over the image. It's also used in conjunction with the weight setting for sorting the avatars."),
'#size' => 48,
'#default_value' => $name,
);
$form['avatar_weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#delta' => 100,
'#description' => t('Avatars with a lower weight appear before higher weighted avatars in lists.'),
'#default_value' => $weight,
);
$form['permissions'] = array(
'#type' => 'fieldset',
'#title' => t('Permissions'),
'#weight' => 1,
);
$form['permissions']['access'] = array(
'#type' => 'checkboxes',
'#title' => t('User Roles'),
'#default_value' => $avs_access,
'#options' => $roles,
'#description' => t('Only the checked roles will be able to see this avatar icon; if no roles are checked, access will not be restricted.'),
);
if (module_exists('og')) {
$form['permissions']['og_access'] = array(
'#type' => 'checkboxes',
'#title' => t('Organic Groups'),
'#default_value' => $og_access,
'#options' => og_all_groups_options(),
'#description' => t('Only users in the checked organic groups will be able to see this avatar icon; if no groups are checked, access will not be restricted.'),
);
}
$form['update'] = array(
'#type' => 'submit',
'#value' => t('Update'),
'#weight' => 9,
'#submit' => array(
'avatar_selection_edit_update_form_submit',
),
);
$form['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#weight' => 10,
'#submit' => array(
'avatar_selection_edit_delete_form_submit',
),
);
}
}
return $form;
}