Skip to content
Snippets Groups Projects
Commit cb34190d authored by Joel Brockbank's avatar Joel Brockbank Committed by Mikke Schirén
Browse files

Issue #2633668 by potop, joel_osc: Views Support

parent b1089574
No related merge requests found
......@@ -3,3 +3,6 @@ description = Allows users to exclude certain nodes from being indexed.
core = 7.x
package = Search
dependencies[] = search_api
files[] = views/handlers/search_api_exclude_views_handler_filter_status.inc
......@@ -224,3 +224,58 @@ function search_api_exclude_remove_node($nid) {
->condition('nid', $nid)
->execute();
}
/**
* Implements hook_action_info().
*/
function search_api_exclude_action_info() {
$actions = array();
$actions['search_api_exclude_set_status_action'] = array(
'type' => 'node',
'label' => t('Exclude node from Search API'),
'behavior' => array('changes_property'),
'configurable' => FALSE,
'vbo_configurable' => FALSE,
'triggers' => array('any'),
);
$actions['search_api_exclude_reset_status_action'] = array(
'type' => 'node',
'label' => t('Include node into Search API'),
'behavior' => array('changes_property'),
'configurable' => FALSE,
'vbo_configurable' => FALSE,
'triggers' => array('any'),
);
return $actions;
}
/**
* Action function.
*
* Removes node from the list of excluded from Search API.
*/
function search_api_exclude_reset_status_action(&$node, $context) {
search_api_exclude_remove_node($node->nid);
}
/**
* Action function.
*
* Excludes node from Search API.
*/
function search_api_exclude_set_status_action(&$node, $context) {
search_api_exclude_add_node($node->nid);
}
/**
*
*/
function search_api_exclude_views_api() {
return array(
'api' => 3.0,
'path' => drupal_get_path('module', 'search_api_exclude') . '/views',
);
}
<?php
/**
* @file
* Definition of search_api_exclude_views_handler_filter_status.
*/
/**
* Filter by Search API exclude status.
*
* @ingroup views_filter_handlers
*/
class search_api_exclude_views_handler_filter_status extends views_handler_filter_boolean_operator {
/**
*
*/
function query() {
$table = $this->ensure_my_table();
if ($this->value == 1) {
$this->query->add_where_expression($this->options['group'], "$table.nid IS NOT NULL");
}
elseif ($this->value == 0) {
$this->query->add_where_expression($this->options['group'], "$table.nid IS NULL");
}
}
}
<?php
/**
* @file
* Views hooks implemented for the Search API Exclude module.
*/
/**
* Implements hook_views_data().
*/
function search_api_exclude_views_data() {
$data = array();
$data['search_api_exclude']['table']['group'] = t('Search API Exclude');
$data['search_api_exclude']['table']['base'] = array(
'field' => 'nid', // This is the identifier field for the view.
'title' => t('Search API Exclude'),
);
$data['search_api_exclude']['table']['join'] = array(
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
'type' => 'LEFT',
),
);
$data['search_api_exclude']['nid'] = array(
'title' => t('Exclude status'),
'help' => t('Whether or not the content is excluded from Search API.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
'output formats' => array(
'excluded-notexcluded' => array(t('Excluded'), t('Not excluded')),
),
),
'filter' => array(
'handler' => 'search_api_exclude_views_handler_filter_status',
'label' => t('Excluded'),
'type' => 'yes-no',
'use equal' => TRUE, // Use status = 1 instead of status <> 0 in WHERE statment
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
return $data;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment