Browse Source

added filter

main
astanley 1 week ago
parent
commit
5c896e5d32
  1. 3
      config/schema/islandora_mirador_annotation.schema.yml
  2. 15
      islandora_mirador_annotation.views.inc
  3. 49
      src/Plugin/views/filter/HasAnnotatedMemberPages.php

3
config/schema/islandora_mirador_annotation.schema.yml

@ -0,0 +1,3 @@
views.filter.has_annotated_member_pages:
type: views.filter.boolean
label: 'Has annotated member pages'

15
islandora_mirador_annotation.views.inc

@ -0,0 +1,15 @@
<?php
/**
* Implements hook_views_data_alter().
*/
function islandora_mirador_annotation_views_data_alter(array &$data) {
$data['node_field_data']['has_annotated_member_pages'] = [
'title' => t('Has annotated member pages'),
'help' => t('Whether this node has member nodes containing Mirador annotations.'),
'filter' => [
'id' => 'has_annotated_member_pages',
'type' => 'yes-no',
],
];
}

49
src/Plugin/views/filter/HasAnnotatedMemberPages.php

@ -0,0 +1,49 @@
<?php
namespace Drupal\islandora_mirador_annotation\Plugin\views\filter;
use Drupal\views\Attribute\ViewsFilter;
use Drupal\views\Plugin\views\filter\BooleanOperator;
/**
* Filters content by the presence of annotated member nodes.
*/
#[ViewsFilter('has_annotated_member_pages')]
class HasAnnotatedMemberPages extends BooleanOperator {
/**
* {@inheritdoc}
*/
public function query() {
$this->ensureMyTable();
$operator = $this->value ? 'EXISTS' : 'NOT EXISTS';
$expression = "
$operator (
SELECT 1
FROM {node__field_member_of} member
INNER JOIN {islandora_mirador_annotation} annotation
ON member.entity_id = CAST(
SUBSTRING_INDEX(
SUBSTRING_INDEX(
annotation.canvas_id,
'/node/',
-1
),
'/',
1
) AS UNSIGNED
)
WHERE member.field_member_of_target_id = {$this->tableAlias}.nid
AND member.deleted = 0
)
";
$this->query->addWhereExpression(
$this->options['group'],
$expression
);
}
}
Loading…
Cancel
Save