Skip to content

Commit

Permalink
Merge pull request #258 from nysenate/feature/aten-nys-182
Browse files Browse the repository at this point in the history
NYS-182: Fixes event filter timeout issue and updates senator filter to only show active senators
  • Loading branch information
routinet authored Nov 13, 2024
2 parents 8a86f55 + ae1aa45 commit 0bcb6b6
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 61 deletions.
102 changes: 41 additions & 61 deletions config/sync/views.view.events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ dependencies:
- node.type.public_hearing
- node.type.session
- taxonomy.vocabulary.committees
- taxonomy.vocabulary.senator
- views.view.global_promo_banner
module:
- address
Expand All @@ -25,6 +24,7 @@ dependencies:
- datetime_range
- link
- node
- nys_calendar
- options
- taxonomy
- user
Expand Down Expand Up @@ -1251,6 +1251,16 @@ display:
collapsible: false
collapsible_disable_automatic_open: false
is_secondary: false
active_senators_filter:
plugin_id: default
advanced:
sort_options: false
rewrite:
filter_rewrite_values: '- Any -|Filter By Senator'
filter_rewrite_values_key: false
collapsible: false
collapsible_disable_automatic_open: false
is_secondary: false
access:
type: perm
options:
Expand Down Expand Up @@ -1459,45 +1469,41 @@ display:
hierarchy: false
limit: true
error_message: true
field_senator_multiref_target_id:
id: field_senator_multiref_target_id
active_senators_filter:
id: active_senators_filter
table: node__field_senator_multiref
field: field_senator_multiref_target_id
field: active_senators_filter
relationship: none
group_type: group
admin_label: ''
plugin_id: taxonomy_index_tid
operator: or
value: { }
plugin_id: active_senators_filter
operator: '='
value: All
group: 1
exposed: true
expose:
operator_id: field_senator_multiref_target_id_op
operator_id: ''
label: ''
description: ''
use_operator: false
operator: field_senator_multiref_target_id_op
operator: active_senators_filter_op
operator_limit_selection: false
operator_list: { }
identifier: field_senator_multiref_target_id
identifier: active_senators_filter
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
anonymous: '0'
administrator: '0'
web_administrator: '0'
frontpage_editor: '0'
senator: '0'
microsite_content_producer: '0'
legislative_correspondent: '0'
student_programs: '0'
constituent: '0'
senate_services: '0'
student_contest_judge: '0'
experimental_content_producer: '0'
reduce: false
comment_moderator: '0'
is_grouped: false
group_info:
label: ''
Expand All @@ -1510,12 +1516,6 @@ display:
default_group: All
default_group_multiple: { }
group_items: { }
reduce_duplicates: false
vid: senator
type: select
hierarchy: false
limit: true
error_message: true
field_date_range_value:
id: field_date_range_value
table: node__field_date_range
Expand Down Expand Up @@ -3007,45 +3007,41 @@ display:
hierarchy: false
limit: true
error_message: true
field_senator_multiref_target_id:
id: field_senator_multiref_target_id
active_senators_filter:
id: active_senators_filter
table: node__field_senator_multiref
field: field_senator_multiref_target_id
field: active_senators_filter
relationship: none
group_type: group
admin_label: ''
plugin_id: taxonomy_index_tid
operator: or
value: { }
plugin_id: active_senators_filter
operator: '='
value: All
group: 1
exposed: true
expose:
operator_id: field_senator_multiref_target_id_op
operator_id: ''
label: ''
description: ''
use_operator: false
operator: field_senator_multiref_target_id_op
operator: active_senators_filter_op
operator_limit_selection: false
operator_list: { }
identifier: field_senator_multiref_target_id
identifier: active_senators_filter
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
anonymous: '0'
administrator: '0'
web_administrator: '0'
frontpage_editor: '0'
senator: '0'
microsite_content_producer: '0'
legislative_correspondent: '0'
student_programs: '0'
constituent: '0'
senate_services: '0'
student_contest_judge: '0'
experimental_content_producer: '0'
reduce: false
comment_moderator: '0'
is_grouped: false
group_info:
label: ''
Expand All @@ -3058,12 +3054,6 @@ display:
default_group: All
default_group_multiple: { }
group_items: { }
reduce_duplicates: false
vid: senator
type: select
hierarchy: false
limit: true
error_message: true
field_date_range_value:
id: field_date_range_value
table: node__field_date_range
Expand Down Expand Up @@ -3332,45 +3322,41 @@ display:
hierarchy: false
limit: true
error_message: true
field_senator_multiref_target_id:
id: field_senator_multiref_target_id
active_senators_filter:
id: active_senators_filter
table: node__field_senator_multiref
field: field_senator_multiref_target_id
field: active_senators_filter
relationship: none
group_type: group
admin_label: ''
plugin_id: taxonomy_index_tid
operator: or
value: { }
plugin_id: active_senators_filter
operator: '='
value: All
group: 1
exposed: true
expose:
operator_id: field_senator_multiref_target_id_op
operator_id: ''
label: ''
description: ''
use_operator: false
operator: field_senator_multiref_target_id_op
operator: active_senators_filter_op
operator_limit_selection: false
operator_list: { }
identifier: field_senator_multiref_target_id
identifier: active_senators_filter
required: false
remember: false
multiple: false
remember_roles:
authenticated: authenticated
anonymous: '0'
administrator: '0'
web_administrator: '0'
frontpage_editor: '0'
senator: '0'
microsite_content_producer: '0'
legislative_correspondent: '0'
student_programs: '0'
constituent: '0'
senate_services: '0'
student_contest_judge: '0'
experimental_content_producer: '0'
reduce: false
comment_moderator: '0'
is_grouped: false
group_info:
label: ''
Expand All @@ -3383,12 +3369,6 @@ display:
default_group: All
default_group_multiple: { }
group_items: { }
reduce_duplicates: false
vid: senator
type: select
hierarchy: false
limit: true
error_message: true
field_date_range_value:
id: field_date_range_value
table: node__field_date_range
Expand Down
22 changes: 22 additions & 0 deletions web/modules/custom/nys_calendar/nys_calendar.module
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ function nys_calendar_views_data() {
'field_type' => 'year_only',
],
];
$data['node__field_senator_multiref']['active_senators_filter'] = [
'title' => t('Active senators'),
'filter' => [
'title' => t('Active senators'),
'help' => t('Custom NYS filter to filter on active senators referenced via field_senator_multiref.'),
'group' => t('Content'),
'field' => 'field_senator_multiref_target_id',
'id' => 'active_senators_filter',
],
];
return $data;
}

Expand Down Expand Up @@ -183,8 +193,20 @@ function nys_calendar_views_pre_build(ViewExecutable $view) {
function nys_calendar_form_views_exposed_form_alter(&$form, FormStateInterface $form_state, $form_id) {
switch ($form['#id']) {
case 'views-exposed-form-events-page-1':
$default_date = date('Y-m-d');
case 'views-exposed-form-events-page-2':
$form['date']['#description'] = 'E.g., ' . date('m/d/Y');
if (!isset($default_date)) {
$default_date = date('Y') . date('-m-') . '01';
}
if (
!empty($form_state->getUserInput()['date'])
&& $form_state->getUserInput()['date'] === 'now'
) {
// Ensure default event day and month date filters are set on exposed
// form prior to user input.
$form['date']['#value'] = $default_date;
}
break;
case 'views-exposed-form-events-page-3':
if (!empty($form['date_wrapper']['date_wrapper']['date'])) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace Drupal\nys_calendar\Plugin\views\filter;

use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Attribute\ViewsFilter;
use Drupal\views\Plugin\views\filter\FilterPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Active senators filter.
*/
#[ViewsFilter("active_senators_filter")]
class ActiveSenatorsFilter extends FilterPluginBase {

/**
* Entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManager
*/
public $entityTypeManager;

/**
* Constructs a ActiveSenatorsFilter object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManager $entityTypeManager
* Entity type manager service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManager $entityTypeManager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entityTypeManager;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity_type.manager'),
);
}

/**
* {@inheritdoc}
*/
protected function valueForm(&$form, FormStateInterface $form_state) {
try {
$taxonomy_storage = $this->entityTypeManager
->getStorage('taxonomy_term');
}
catch (\Exception) {
return;
}
$options = [];
$active_senators_tids = $taxonomy_storage
->getQuery()
->accessCheck(FALSE)
->condition('vid', 'senator')
->condition('field_active_senator', TRUE)
->sort('field_senator_name.family')
->execute();
if (!empty($active_senators_tids)) {
$active_senators = $taxonomy_storage->loadMultiple($active_senators_tids);
foreach ($active_senators as $senator) {
$options[$senator->id()] = $senator->label();
}
}
$form['value'] = [
'#type' => 'select',
'#title' => 'Active senators',
'#options' => ['All' => '- Any -'] + $options,
'#default_value' => 'All',
];
}

}

0 comments on commit 0bcb6b6

Please sign in to comment.