function favorites_add_favorite_form in Favorites 7.2
Same name and namespace in other branches
- 6 favorites.module \favorites_add_favorite_form()
- 7 favorites.module \favorites_add_favorite_form()
Form callback for the "add favorite form"
See also
favorites_user_block()
1 string reference to 'favorites_add_favorite_form'
- favorites_block_view in ./
favorites.module - Implements hook_block_view().
File
- ./
favorites.module, line 223 - The favorites module allows users to bookmark any path within a site.
Code
function favorites_add_favorite_form($form, &$form_state) {
global $user;
// Try to get a default value for the title field.
// drupal_get_title() has run through check_plain. This is useless for us
// and needs to be fixed, which only works easily with PHP >= 5.1.
if (function_exists('version_compare') && version_compare(PHP_VERSION, '5.1.0', '>=')) {
$title = htmlspecialchars_decode(drupal_get_title());
}
if (!isset($title)) {
$title = menu_get_active_title();
}
if ($title == '') {
$title = variable_get('site_name', 'Home');
}
$title = strip_tags($title);
$path = strip_tags($_GET['q']);
$query = drupal_http_build_query($_GET);
// Add a collapsible container.
$form = array(
'add' => array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('add this page'),
'title' => array(
'#type' => 'textfield',
'#size' => 20,
'#maxlength' => 255,
'#default_value' => $title,
'#attributes' => array(
'style' => 'width: 90%',
'class' => array(
'favorites-add-textfield',
),
),
),
'submit' => array(
'#type' => 'submit',
'#value' => t("Add"),
'#submit' => array(
'favorites_add_favorite_form_submit',
),
),
'path' => array(
'#type' => 'value',
'#value' => $path,
),
'query' => array(
'#type' => 'value',
'#value' => $query,
),
),
);
//Preserve the current path with query string.
$form_state['redirect'] = array(
$_GET['q'],
array(
'query' => drupal_http_build_query($_GET),
),
);
// Additionally add path and query to the JS settings.
drupal_add_js(array(
'favorites' => array(
'path' => $path,
'query' => $query,
'addCallbackPath' => url('favorites/js/add'),
),
), 'setting');
return $form;
}