-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #258 from nysenate/feature/aten-nys-182
NYS-182: Fixes event filter timeout issue and updates senator filter to only show active senators
- Loading branch information
Showing
3 changed files
with
149 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
web/modules/custom/nys_calendar/src/Plugin/views/filter/ActiveSenatorsFilter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]; | ||
} | ||
|
||
} |