views

How to embed a form element in a Views view

This is how you can embed forms in to a Views view in Drupal 6 with the module Views Embed Form.


//Create a hook_views_embed_form
//Needs to be [your module name] + '_views_embed_form' but can exists in a inc file
function mymodule_views_embed_form() {
//Set a user permission if needed
if (user_access('administer workflow state')) {
return array(
'mymodule_embedded_ticket_form' => t('My form name'),
);
}else{
return array(); //I added this to avoid error message if user has no access to the form
}
}

//Create a form, remember

Some Drupal links for developers

Some good Drupal developer guides or reference pages

Forms API

CCK

Views

Theme

Prerender views in module to add a summary row


/**
* Implementation of hook_views_pre_render().
*/
function mymodule_views_pre_render(&$view) {
if ($view->name == 'myview') {
// perform calculations on each row
$pointsEarned = $pointsPossible = 0;
foreach($view->result as $submission) {
if (is_numeric($submission->node_data_field_pointsearned_field_pointsearned_value)) {
$pointsEarned += $submission->node_data_field_pointsearned_field_pointsearned_value;
$pointsPossible += $submission->node_node_data_field_pointspossible_field_pointspossible_value;
}
}

How to sort views summary on term weight programmatically

This is how you can sort your view on taxonomy term weight programmatically instead of using the default Summary, sorted ascending/descending

/*
* Hook views_pre_execute
*
*/
function mymodule_views_pre_execute(&$view) {
if ($view->name == 'opportunity_summary' && $view->current_display == 'block_1') {
$search = array('ORDER BY term_data_name ASC');
$replace = array('ORDER BY term_data.weight ASC');
$view->build_info['query'] = str_replace($search, $replace, $view->build_info['query']);
$view->build_info['count_query'] = str_replace($search, $replace,

Modify views filter

If you need to modify views filter from your module, e.g when changing settings to a content type, you maybe whant a CCK autocomplete filed to be filtered as well.


/**
* Change views filter according to saved settings
*
* Thank heaven when you can manipulate views arguments in autocomplete CCK :-)
*
*/
function _save_allowed_node_types($node_types) {

$set_types = array();
foreach ($node_types as $key => $value) {
if ($value != "0") {
$set_types[$key] = $value;
}
}

$get_view = db_query('SELECT vid FROM {views_view}

Embed Drupal views in content, template or in your module

This is how you can get the view embedded. Another nice little trick is to actually embed the view in the node content/body, template or a function in your module. This way you don't have to create a region just for the gallery system, and it is so simple that it would be a shame not to do it this way! The only thing you need to do is to edit the node template of your theme, and paste a little snippet of code that will tell drupal which view and which display to embed. The code is like this :

<?php print views_embed_view('view_name', $display_id = 'display_id');?>