ArgumentValidatorTest.php

Same filename in this branch
  1. 11.x core/modules/views/tests/src/Kernel/Plugin/ArgumentValidatorTest.php
  2. 11.x core/modules/views_ui/tests/src/Functional/ArgumentValidatorTest.php
Same filename and directory in other branches
  1. 9 core/modules/views/tests/src/Kernel/Plugin/ArgumentValidatorTest.php
  2. 9 core/modules/views/tests/modules/views_test_data/src/Plugin/views/argument_validator/ArgumentValidatorTest.php
  3. 9 core/modules/views_ui/tests/src/Functional/ArgumentValidatorTest.php
  4. 8.9.x core/modules/views/tests/src/Kernel/Plugin/ArgumentValidatorTest.php
  5. 8.9.x core/modules/views/tests/modules/views_test_data/src/Plugin/views/argument_validator/ArgumentValidatorTest.php
  6. 8.9.x core/modules/views_ui/tests/src/Functional/ArgumentValidatorTest.php
  7. 10 core/modules/views/tests/src/Kernel/Plugin/ArgumentValidatorTest.php
  8. 10 core/modules/views/tests/modules/views_test_data/src/Plugin/views/argument_validator/ArgumentValidatorTest.php
  9. 10 core/modules/views_ui/tests/src/Functional/ArgumentValidatorTest.php

Namespace

Drupal\views_test_data\Plugin\views\argument_validator

File

core/modules/views/tests/modules/views_test_data/src/Plugin/views/argument_validator/ArgumentValidatorTest.php

View source
<?php

namespace Drupal\views_test_data\Plugin\views\argument_validator;

use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Plugin\views\argument_validator\ArgumentValidatorPluginBase;
use Drupal\views\Attribute\ViewsArgumentValidator;

/**
 * Defines an argument validator test plugin.
 */
class ArgumentValidatorTest extends ArgumentValidatorPluginBase {
    
    /**
     * {@inheritdoc}
     */
    public function calculateDependencies() {
        return [
            'content' => [
                'ArgumentValidatorTest',
            ],
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    protected function defineOptions() {
        $options = parent::defineOptions();
        $options['test_value'] = [
            'default' => '',
        ];
        return $options;
    }
    
    /**
     * {@inheritdoc}
     */
    public function validateArgument($arg) {
        if ($arg === 'this value should be replaced') {
            // Set the argument to a numeric value so this is valid on PostgreSQL for
            // numeric fields.
            $this->argument->argument = '1';
            return TRUE;
        }
        return $arg == $this->options['test_value'];
    }

}

Classes

Title Deprecated Summary
ArgumentValidatorTest Defines an argument validator test plugin.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.