Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/Plugin/views/filter/Selective.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

namespace Drupal\views_selective_filters\Plugin\views\filter;

use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Form\FormState;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\filter\InOperator;
use Drupal\views\ViewExecutable;
use Drupal\views\Views;
use Drupal\Component\Utility\Html;

/**
* Views filter handler for selective values.
Expand Down Expand Up @@ -172,9 +172,9 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
'#theme' => 'status_messages',
'#message_list' => ['warning' => [$this->t('This filter is always exposed to users.')]],
'#status_headings' => [
'status' => t('Status message'),
'error' => t('Error message'),
'warning' => t('Warning message'),
'status' => $this->t('Status message'),
'error' => $this->t('Error message'),
'warning' => $this->t('Warning message'),
],
)));
// Remove option to unexpose filter. Tried to disable, but did not work.
Expand Down Expand Up @@ -374,10 +374,11 @@ protected function getOids() {

// Check to see if the user remembered to add the field.
if (empty($fields)) {
drupal_set_message(t('Selective query filter must have corresponding field added to view with Administrative Name set to "@name" and Base Type "@type"',
array(
\Drupal::messenger()->addMessage('Selective query filter must have corresponding field added to view with Administrative Name set to "@name" and Base Type "@type"',
[
'@name' => $ui_name,
'@type' => $base_field)),
'@type' => $base_field
],
'error');
return [];
}
Expand All @@ -399,10 +400,11 @@ protected function getOids() {
($field_options['relationship'] === $this->options['relationship']);

if (!$equal) {
drupal_set_message(t('Selective filter "@name": relationship of field and filter must match.',
array(
\Drupal::messenger()->addMessage('Selective filter "@name": relationship of field and filter must match.',
[
'@name' => $ui_name,
'@type' => $base_field)),
'@type' => $base_field,
],
'error');
return [];
}
Expand Down Expand Up @@ -456,7 +458,7 @@ protected function getOids() {
foreach ((array) $keys as $key) {
$value = NULL;

if (NULL !== $entityTypeStorage) {
if (NULL !== $entityTypeStorage && $key) {
$entity = $entityTypeStorage->load($key);

if ($entity) {
Expand All @@ -469,7 +471,7 @@ protected function getOids() {
}

if (NULL !== $value) {
$oids[$key] = SafeMarkup::checkPlain($value);
$oids[$key] = Html::escape($value);
}
}
}
Expand Down Expand Up @@ -500,7 +502,7 @@ protected function getOids() {

// If limit exceeded this field is not good for being "selective".
if (!empty($max_items) && count($oids) === $max_items) {
drupal_set_message(t('Selective filter "@field" has limited the amount of total results. Please, review you query configuration.', array('@field' => $ui_name)), 'warning');
\Drupal::messenger()->addMessage('Selective filter "@field" has limited the amount of total results. Please, review you query configuration.', ['@field' => $ui_name], 'warning');
}

static::$results[$signature] = $oids;
Expand Down
3 changes: 2 additions & 1 deletion views_selective_filters.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ type: module
description: Restrict exposed filter values to those present in the result set.
package: Views
core: 8.x
core_version_requirement: ^8 || ^9 || ^10
dependencies:
- views
- drupal:views