I want to contextually filter my View with a boolean field, for which the "On" value is "New," so using a URL like /view/url/new.
I first tried basic validation, but that would only work if my URL were /view/url/1.
So I wrote my own validation plugin to validate "New" as if it were "1".
<?php
namespace Drupal\my_module_validation\Plugin\views\argument_validator;
use Drupal\views\Plugin\views\argument_validator\ArgumentValidatorPluginBase;
/**
* Validate the New boolean.
*
* @ingroup views_argument_validate_plugins
*
* @ViewsArgumentValidator(
* id = "my_module_validation",
* title = @Translation("MYMODULE Validation")
* )
*/
class MyModuleValidation extends ArgumentValidatorPluginBase {
public function validateArgument($argument) {
if($argument == 'new' || $argument == 'New' || $argument == '1') {
return TRUE;
}
return FALSE;
}
}
So I'm able to apply this fine (and I can tell it's being used with a drupal_set_message() thrown inside that block), but it still doesn't work. Results only appear if I add the /view/url/1 and not the /view/url/new like I want.
Please help me understand what I've done wrong and how I can fix it.
$argument
is what you expect it to be at that point?