diff --git a/search_api_exclude.info b/search_api_exclude.info index e4fabbf..2a45180 100644 --- a/search_api_exclude.info +++ b/search_api_exclude.info @@ -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 + diff --git a/search_api_exclude.module b/search_api_exclude.module index 72207eb..c75ad3e 100644 --- a/search_api_exclude.module +++ b/search_api_exclude.module @@ -222,3 +222,55 @@ 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', + ); +} diff --git a/views/handlers/search_api_exclude_views_handler_filter_status.inc b/views/handlers/search_api_exclude_views_handler_filter_status.inc new file mode 100644 index 0000000..9c71fdc --- /dev/null +++ b/views/handlers/search_api_exclude_views_handler_filter_status.inc @@ -0,0 +1,23 @@ +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"); + } + } +} diff --git a/views/search_api_exclude.views.inc b/views/search_api_exclude.views.inc new file mode 100644 index 0000000..93490ef --- /dev/null +++ b/views/search_api_exclude.views.inc @@ -0,0 +1,48 @@ + '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