User the following function
$view = views_get_view('your_view_name');
$view->set_display('default');
$view->init_handlers();
$form_state = array(
'view' => $view,
'display' => $view->display_handler->display,
'method' => 'get',
'rerender' => TRUE,
'no_redirect' => TRUE,
);
$output = drupal_build_form('views_exposed_form', $form_state);
return $output;
Tuesday, June 28, 2011
Monday, June 27, 2011
PHP – parse a string between two strings
function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
$fullstring = "this is my [tag]dog[/tag]";
$parsed = get_string_between($fullstring, "[tag]", "[/tag]");
echo $parsed; // (result = dog)
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
$fullstring = "this is my [tag]dog[/tag]";
$parsed = get_string_between($fullstring, "[tag]", "[/tag]");
echo $parsed; // (result = dog)
Friday, June 24, 2011
Customizing the user profile layout
Step 1 - is to override the default User Profile page layout by uploading a custom user-profile.tpl.php* file to your active theme folder.
Drupal will automatically detect the presence of your custom user-profile.tpl.php and override the default user profile layout. To make this happen, you need to rebuild the theme registry, which you can do by clearing the caches (for example using the button on the admin/settings/performance page), or simply by visiting the admin/build/modules page.
* note that in Drupal 6.x, your custom user profile layout file name uses a hyphen, instead of an underscore.
Step 2 - is to customize your user-profile.tpl.php layout file.
By default, all user profile data is printed out with the $user_profile variable. If there is a need to break it up you can use $profile instead.
As an example, the following snippet inserted in your custom user-profile.tpl.php will display the default user profile layout.
Available variables:
$user_profile: All user profile data. Ready for print.
$profile: Keyed array of profile categories and their items or other data provided by modules.
To check for all available data within $profile, insert the following snippet at the bottom of your custom user-profile.tpl.php.
Step 3 - Load profile variables
If you want to load the profile variables (profile module) you can use this code in user-profile.tpl.php
profile_load_profile($account);
// now you can call the profile field like profile_firstname
echo $account->profile_firstname;
Drupal will automatically detect the presence of your custom user-profile.tpl.php and override the default user profile layout. To make this happen, you need to rebuild the theme registry, which you can do by clearing the caches (for example using the button on the admin/settings/performance page), or simply by visiting the admin/build/modules page.
* note that in Drupal 6.x, your custom user profile layout file name uses a hyphen, instead of an underscore.
Step 2 - is to customize your user-profile.tpl.php layout file.
By default, all user profile data is printed out with the $user_profile variable. If there is a need to break it up you can use $profile instead.
As an example, the following snippet inserted in your custom user-profile.tpl.php will display the default user profile layout.
Available variables:
$user_profile: All user profile data. Ready for print.
$profile: Keyed array of profile categories and their items or other data provided by modules.
To check for all available data within $profile, insert the following snippet at the bottom of your custom user-profile.tpl.php.
Available variables
The following is a list of variables that is available to your custom user-profile.tpl.php.
print ''. check_plain(print_r($profile, 1)) .'';
Step 3 - Load profile variables
If you want to load the profile variables (profile module) you can use this code in user-profile.tpl.php
profile_load_profile($account);
// now you can call the profile field like profile_firstname
echo $account->profile_firstname;
Thursday, June 23, 2011
Displaying exposed filter form for views in Drupal 6
$view = views_get_view('your_view_name');
$view->set_display('default');
$view->init_handlers();
$form_state = array(
'view' => $view,
'display' => $view->display_handler->display,
'method' => 'get',
'rerender' => TRUE,
'no_redirect' => TRUE,
);
$output = drupal_build_form('views_exposed_form', $form_state);
return $output;
$view->set_display('default');
$view->init_handlers();
$form_state = array(
'view' => $view,
'display' => $view->display_handler->display,
'method' => 'get',
'rerender' => TRUE,
'no_redirect' => TRUE,
);
$output = drupal_build_form('views_exposed_form', $form_state);
return $output;
Change Views Exposed Filter Form Select Element To A List Of Checkboxes
Three steps for doing this.
/**
* Implementation of HOOK_theme.
*
* @return array An array of theme hooks.
*/
function mymodule_hooks_theme() {
return array(
'select_as_checkboxes' => array(
'function' => 'theme_select_as_checkboxes'
),
);
}
/**
* Implementation of HOOK_form_alter().
*
* @param array $form The form
* @param string $form_state The current state of the form.
*/
function mymodule_hooks_form_views_exposed_form_alter(&$form, &$form_state)
{
// We only want to change a certain form, so stop Drupal looking at any
// other exposed view form
if ($form['#id'] == 'views-exposed-form-myview-page-1') {
// Make the select box appear as a list of checkboxes
$form['formelement']['#theme'] = 'select_as_checkboxes';
$form['anotherformelement']['#theme'] = 'select_as_checkboxes';
}
}
function theme_select_as_checkboxes($element) {
$output = '';
$selected_options = (array) $element['#post'][$element['#name']]; // the selected keys from #options
foreach($element['#options'] as $key => $value) {
$id = $element['#id'] . '-' . $key; // custom
// is this option selected?
$selected = (array_search($key, $selected_options) !== false); // (returns key or false)
$checkbox = '';
$output .= '' . "\n";
}
return theme_form_element($element, $output); // wraps it neatly
}
/**
* Implementation of HOOK_theme.
*
* @return array An array of theme hooks.
*/
function mymodule_hooks_theme() {
return array(
'select_as_checkboxes' => array(
'function' => 'theme_select_as_checkboxes'
),
);
}
/**
* Implementation of HOOK_form_alter().
*
* @param array $form The form
* @param string $form_state The current state of the form.
*/
function mymodule_hooks_form_views_exposed_form_alter(&$form, &$form_state)
{
// We only want to change a certain form, so stop Drupal looking at any
// other exposed view form
if ($form['#id'] == 'views-exposed-form-myview-page-1') {
// Make the select box appear as a list of checkboxes
$form['formelement']['#theme'] = 'select_as_checkboxes';
$form['anotherformelement']['#theme'] = 'select_as_checkboxes';
}
}
function theme_select_as_checkboxes($element) {
$output = '';
$selected_options = (array) $element['#post'][$element['#name']]; // the selected keys from #options
foreach($element['#options'] as $key => $value) {
$id = $element['#id'] . '-' . $key; // custom
// is this option selected?
$selected = (array_search($key, $selected_options) !== false); // (returns key or false)
$checkbox = '';
$output .= '' . "\n";
}
return theme_form_element($element, $output); // wraps it neatly
}
Wednesday, June 22, 2011
user_external_login Perform standard Drupal login operations for a user object.
D6 user_external_login($account, $edit = array())
Perform standard Drupal login operations for a user object.
The user object must already be authenticated. This function verifies that the user account is not blocked/denied and then performs the login, updates the login timestamp in the database, invokes hook_user('login'), and regenerates the session.
Perform standard Drupal login operations for a user object.
The user object must already be authenticated. This function verifies that the user account is not blocked/denied and then performs the login, updates the login timestamp in the database, invokes hook_user('login'), and regenerates the session.
Make sticky tableheaders optional
Drupal 6:
// Sticky tableheaders always enabled.
$table = theme('table', $headers, $rows, array(), NULL, array());
Drupal 7:
// With sticky tableheaders.
theme('table', array('header' => $header, 'rows' => $rows));
// Without sticky tableheaders.
theme('table', array('header' => $header, 'rows' => $rows, 'sticky' => FALSE));
// Sticky tableheaders always enabled.
$table = theme('table', $headers, $rows, array(), NULL, array());
Drupal 7:
// With sticky tableheaders.
theme('table', array('header' => $header, 'rows' => $rows));
// Without sticky tableheaders.
theme('table', array('header' => $header, 'rows' => $rows, 'sticky' => FALSE));
Subscribe to:
Posts (Atom)
