Posts Tagged views

Similarterms module in drupal.org

This Drupal module attempts to provide context for content items by displaying a view block with links to other similar content. Similarity is based on the taxonomy terms assigned to content. Views are available based on similarity within each of the defined vocabularies for a site as well as similarity within all vocabularies.

What does this really mean? How should you use this module?

1) Create a freetagging vocabulary called “Tags” assigned to the content types on which you’d like to display the “Similar” view block.
2) Enable the view block called “Similar entries from the Tags vocabulary”.
3) Add keyword tags to the content.

https://www.drupal.org/project/similarterms

Advertisements

, , ,

Leave a comment

Creating custom filters with drupal and views

If you want to know how to create custom filters with Drupal and view please follow the step from the link

http://www.chadcf.com/blog/creating-custom-filters-drupal-and-views

But you need to remember some missing information :-

it is done in views api 2 , so function definition you need to change. for example

$this->query->add_where($this->options[‘group’], “term_node.tid = %d”, $value); should be

$this->query->add_where($this->options[‘group’], “term_node.tid”, $value,’=’);

ofcourse remember to add those files inside module.info file, otherwise you will see broken handlers in your view.

Leave a comment

How to disable views programmatically when the offering module is disabled

Here is a snippet of code you would put in mymodule.install

/**
* Disable workbench views
*/
function mymodule_update_7001() {
// a list of views (their view name) I want to disable
$viewnames = array(
‘workbench_current_user’,
‘workbench_edited’,
);
// grab list of views that are already disabled
$views_status = variable_get(‘views_defaults’, array());
// add our views to be disabled to the list
foreach ($viewnames as $key => $viewname) {
$views_status[$viewname] = TRUE;
}
// reset the variable with the new list
variable_set(‘views_defaults’, $views_status);
// empty cache now
if (function_exists(‘views_invalidate_cache’)) {
views_invalidate_cache();
}
}

Leave a comment

Solution – How to work Ajax property in view exposed filter in drupal 7

It takes a lot of time to find out what is exact reason views exposed filter does not work with #ajax property in form element. In order for Ajax to work, we need the form build info where we check i #ajax has been added to any form elements, and if so, pass this info as settings via Javascript, which get attached to the submitted form on Ajax form submission.

Sample code in your .module file for Drupal 7 as follow :-

/**
* Implements hook_form_views_exposed_form_alter().
*/

function MYMODULE_form_views_exposed_form_alter(&$form, $form_state) {
$form += MYMODULE_view_enable_ajax($form, $form_state);
}

/* * *
* functions for enable ajax call for exposed form elements in views.
*/

function MYMODULE_view_enable_ajax($form, $form_state) {
// Since the exposed form is a GET form, we don’t want it to send a wide
// variety of information.
$form[‘form_build_id’][‘#access’] = FALSE;
$form[‘form_token’][‘#access’] = FALSE;
$form[‘form_id’][‘#access’] = FALSE;

// In order for Ajax to work, we need the form build info. Here we check if
// #ajax has been added to any form elements, and if so, pass this info as
// settings via Javascript, which get attached to the submitted form on Ajax
// form submissions.
foreach (element_children($form) as $key) {
if (isset($form[$key][‘#ajax’])) {
$form[‘#attached’][‘js’][] = array(
‘type’ => ‘setting’,
‘data’ => array(
‘exposed_form_info’ => array(
‘form_id’ => $form[‘#form_id’],
‘form_build_id’ => $form[‘#build_id’],
‘form_token’ => $form[‘#token’],
),
),
);
$form[‘#attached’][‘js’][] = array(
‘type’ => ‘inline’,
‘weight’ => 100,
‘data’ => ‘(function ($) {
Drupal.behaviors.ViewsExposedFormAjax = {
attach: function(context, settings) {
for (ajax_object in Drupal.ajax) {
if (Drupal.ajax[ajax_object].options) {
jQuery.extend(Drupal.ajax[ajax_object].options.data, Drupal.settings.exposed_form_info);
}
}
}
};
})(jQuery);’,
);
break;
}
}

return $form;
}

,

4 Comments