Skip to content

Commit

Permalink
Inital port to Backdrop CMS and coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
yorkshire-pudding committed Apr 25, 2023
1 parent c8d0964 commit e58f3fe
Show file tree
Hide file tree
Showing 7 changed files with 480 additions and 65 deletions.
339 changes: 339 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

110 changes: 110 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
Other View Filter
========
<!--
The first paragraph of this file should be kept short as it will be used as the
project summary on BackdropCMS.org. Aim for about 240 characters (three lines at
80 characters each).
All lines in this file should be no more than 80 characters long for legibility,
unless including a URL or example that requires the line to not wrap.
|<- - - - - - - This line is exactly 80 characters for reference - - - - - - ->|
Detail in READMEs should be limited to the minimum required for installation and
getting started. More detailed documentation should be moved to a GitHub wiki
page; for example: https://github.com/backdrop-contrib/setup/wiki/Documentation.
-->

Other View Filter enables you to filter the contents of one view by the
contents of another view. You can either filter by items that exist in the
other view or filter by items that do not exist in the other view.

You may wish to include two view displays on on one page and filter out items
in one view that are included in the other view. Or it may be that you need to
filter a view in a way that cannot be done in a single display.

To minimize the cost to performance of running multiple views queries, the
number of instances of this filter on the same display should be kept to a
minimum and caching should be employed liberally. Using more than 1 view for
filtering will strongly decrease your site performance. To minimize performance
decreasing use simple and cached views.

Usage
---------------------
1. In the view from which you wish exclude or include items, add filter "Other
view result".
2. In the filter criterion screen choose the "View: display" combination you
want to filter by.
3. Select the Operator to:
- include items from the other view (Is one of);
- exclude items from the other view (Is not one of);
4. Apply to this display or to all displays.
5. Save the view.

Requirements
------------
<!--
List any dependencies here. Remove this section if not needed.
-->

This module requires that the following modules are also enabled:

- Views (Core - Enabled by default)

Installation
------------
<!--
List the steps needed to install and configure the module. Add/remove steps as
necessary.
-->

- Install this module using the official Backdrop CMS instructions at
https://docs.backdropcms.org/documentation/extend-with-modules.

Issues
------
<!--
Link to the repo's issue queue.
-->

Bugs and Feature Requests should be reported in the Issue Queue:
https://github.com/backdrop-contrib/other_view_filter/issues.


Credits
-------
- Ported to Backdrop CMS by - [Martin Price](https://github.com/yorkshire-pudding) - [System Horizons](https://www.systemhorizons.co.uk).
- Port sponsored by [System Horizons](https://www.systemhorizons.co.uk).

Current Maintainers
-------------------
<!--
List the current maintainer(s) of the module, and note if this module needs
new/additional maintainers.
-->

- [Martin Price](https://github.com/yorkshire-pudding) - [System Horizons Ltd](https://www.systemhorizons.co.uk)
- Collaboration and co-maintainers welcome!

Credits
-------
<!--
Give credit where credit's due.
If this is a Drupal port, state who ported it, and who wrote the original Drupal
module. If this module is based on another project, or uses third-party
libraries, list them here. You can also mention any organisations/companies who
sponsored the module's development.
-->

- Ported to Backdrop CMS by - [Martin Price](https://github.com/yorkshire-pudding) - [System Horizons Ltd](https://www.systemhorizons.co.uk).
- Port sponsored by [System Horizons Ltd](https://www.systemhorizons.co.uk).
- Originally written for Drupal by [Anton Ivanov](https://www.drupal.org/u/antonnavi).

License
-------
<!--
Mention what license this module is released under, and where people can find
it.
-->

This project is GPL v2 software.
See the LICENSE.txt file in this directory for complete text.
43 changes: 0 additions & 43 deletions README.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<?php

/**
* @file
* Definition of views_handler_filter_entity_other_view filter.
* Contains other_view_filter_handler_filter_view.
*/

/**
* Filter class which allows to filter by certain bundles of an entity.
*
* This class provides workarounds for taxonomy and comment.
* Filter class which allows to filter by another view.
*
* @ingroup views_filter_handlers
*/
class other_view_filter_handler_filter_view extends views_handler_filter_in_operator {
var $value_form_type = 'select';
/**
* Stores the form type.
*
* @var string
*/
public $value_form_type = 'select';

/**
* Stores the entity type on which the filter filters.
Expand All @@ -25,23 +27,23 @@ class other_view_filter_handler_filter_view extends views_handler_filter_in_oper
/**
* {@inheritdoc}
*/
function init(&$view, &$options) {
public function init(&$view, &$options) {
parent::init($view, $options);
$this->get_entity_type();
}

/**
* {@inheritdoc}
*/
function construct() {
public function construct() {
parent::construct();
$this->value_title = t('View: display');
}

/**
* {@inheritdoc}
*/
function option_definition() {
public function option_definition() {
$options = parent::option_definition();
// Set "not in" operator to have usual use case selected by default.
$options['operator']['default'] = 'not in';
Expand All @@ -54,7 +56,7 @@ class other_view_filter_handler_filter_view extends views_handler_filter_in_oper
* @return string
* The entity type on the filter.
*/
function get_entity_type() {
public function get_entity_type() {
if (isset($this->entity_type)) {
return $this->entity_type;
}
Expand Down Expand Up @@ -84,7 +86,7 @@ class other_view_filter_handler_filter_view extends views_handler_filter_in_oper
/**
* {@inheritdoc}
*/
function value_form(&$form, &$form_state) {
public function value_form(&$form, &$form_state) {
parent::value_form($form, $form_state);
unset($form['value']['#options']['all']);

Expand All @@ -102,7 +104,7 @@ class other_view_filter_handler_filter_view extends views_handler_filter_in_oper
/**
* Return a list of all available views.
*/
function get_value_options() {
public function get_value_options() {
if (isset($this->value_options)) {
return;
}
Expand Down Expand Up @@ -145,7 +147,7 @@ class other_view_filter_handler_filter_view extends views_handler_filter_in_oper
/**
* {@inheritdoc}
*/
function query() {
public function query() {
$this->ensure_my_table();

// Figure out what this entity id is called (eg. nid, uid, etc.)
Expand Down
14 changes: 7 additions & 7 deletions other_view_filter.info
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name = Other View filter
description = Adds a filter to views that uses the results of another view.
name = Other View Filter
description = Filter views using the results of another view.
backdrop = 1.x
type = module
package = Views
core = 7.x
tags[] = Content
tags[] = Filters
tags[] = Site Architecture

; Handlers
files[] = other_view_filter_handler_filter_view.inc

dependencies[] = ctools
dependencies[] = views
10 changes: 9 additions & 1 deletion other_view_filter.module
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* @file
* Filter that allows requiring or excluding entities selected by another view.
Expand All @@ -13,3 +12,12 @@ function other_view_filter_views_api() {
'api' => 3,
);
}

/**
* Implements hook_autoload_info().
*/
function other_view_filter_autoload_info() {
return array(
'other_view_filter_handler_filter_view' => 'includes/other_view_filter_handler_filter_view.inc',
);
}
1 change: 0 additions & 1 deletion other_view_filter.views.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* @file
* Views hooks for Other View filter module.
Expand Down

0 comments on commit e58f3fe

Please sign in to comment.