Version 1
[yaffs-website] / web / core / modules / views / src / Plugin / views / argument_validator / NumericArgumentValidator.php
diff --git a/web/core/modules/views/src/Plugin/views/argument_validator/NumericArgumentValidator.php b/web/core/modules/views/src/Plugin/views/argument_validator/NumericArgumentValidator.php
new file mode 100644 (file)
index 0000000..7368e06
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+
+namespace Drupal\views\Plugin\views\argument_validator;
+
+use Drupal\Core\Plugin\Context\ContextDefinition;
+
+/**
+ * Validate whether an argument is numeric or not.
+ *
+ * @ingroup views_argument_validate_plugins
+ *
+ * @ViewsArgumentValidator(
+ *   id = "numeric",
+ *   title = @Translation("Numeric")
+ * )
+ */
+class NumericArgumentValidator extends ArgumentValidatorPluginBase {
+
+  public function validateArgument($argument) {
+    return is_numeric($argument);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getContextDefinition() {
+    return new ContextDefinition('integer', $this->argument->adminLabel(), FALSE);
+  }
+
+}