Commit 3b62b84f authored by alexpott's avatar alexpott

Issue #2195083 by Les Lim, ParisLiakos, Xano, gaurav_varshney, ravi.khetri,...

Issue #2195083 by Les Lim, ParisLiakos, Xano, gaurav_varshney, ravi.khetri, fago, jain_deepak: Add a dedicated @Constraint annotation class
parent 1144f479
......@@ -12,7 +12,7 @@
/**
* Checks if a value is a valid entity type.
*
* @Plugin(
* @Constraint(
* id = "Bundle",
* label = @Translation("Bundle", context = "Validation"),
* type = { "entity", "entity_reference" }
......
......@@ -12,7 +12,7 @@
/**
* Validation constraint for the entity changed timestamp.
*
* @Plugin(
* @Constraint(
* id = "EntityChanged",
* label = @Translation("Entity changed", context = "Validation"),
* type = {"entity"}
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\Core\Entity\Constraint\EntityTypeConstraint.
* Contains \Drupal\Core\Entity\Plugin\Validation\Constraint\EntityTypeConstraint.
*/
namespace Drupal\Core\Entity\Plugin\Validation\Constraint;
......@@ -12,7 +12,7 @@
/**
* Checks if a value is a valid entity type.
*
* @Plugin(
* @Constraint(
* id = "EntityType",
* label = @Translation("Entity type", context = "Validation"),
* type = { "entity", "entity_reference" }
......
......@@ -14,7 +14,7 @@
*
* Verifies that referenced entities are valid.
*
* @Plugin(
* @Constraint(
* id = "ReferenceAccess",
* label = @Translation("Entity Reference reference access", context = "Validation")
* )
......
......@@ -14,7 +14,7 @@
*
* Verifies that referenced entities are valid.
*
* @Plugin(
* @Constraint(
* id = "ValidReference",
* label = @Translation("Entity Reference valid reference", context = "Validation")
* )
......
<?php
/**
* @file
* Contains \Drupal\Core\Validation\Annotation\Constraint.
*/
namespace Drupal\Core\Validation\Annotation;
use Drupal\Component\Annotation\Plugin;
/**
* Defines a validation constraint annotation object.
*
* Plugin Namespace: Plugin\Validation\Constraint
*
* For a working example, see
* \Drupal\Core\Validation\Plugin\Validation\Constraint\LengthConstraint
*
* @see \Drupal\Core\Validation\ConstraintManager
* @see \Symfony\Component\Validator\Constraint
* @see hook_validation_constraint_alter()
* @see plugin_api
*
* @Annotation
*/
class Constraint extends Plugin {
/**
* The constraint plugin ID.
*
* @var string
*/
public $id;
/**
* The human-readable name of the constraint plugin.
*
* @ingroup plugin_translatable
*
* @var string|\Drupal\Core\Annotation\Translation
*/
public $label;
/**
* An array of DataType plugin IDs for which this constraint applies. Valid
* values are any types registered by the typed data API, or an array of
* multiple type names. For supporting all types, FALSE may be specified. The
* key defaults to an empty array, which indicates no types are supported.
*
* @var string|string[]|false
*
* @see \Drupal\Core\TypedData\Annotation\DataType
*/
public $type = [];
}
......@@ -26,10 +26,10 @@
* module would have to prefix any constraints with "Profile".
*
* Constraint plugins may specify data types to which support is limited via the
* 'type' key of plugin definitions. Valid values are any types registered via
* the typed data API, or an array of multiple type names. For supporting all
* types FALSE may be specified. The key defaults to an empty array, i.e. no
* types are supported.
* 'type' key of plugin definitions. See
* \Drupal\Core\Validation\Annotation\Constraint for details.
*
* @see \Drupal\Core\Validation\Annotation\Constraint
*/
class ConstraintManager extends DefaultPluginManager {
......@@ -45,7 +45,7 @@ class ConstraintManager extends DefaultPluginManager {
* The module handler to invoke the alter hook with.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/Validation/Constraint', $namespaces, $module_handler);
parent::__construct('Plugin/Validation/Constraint', $namespaces, $module_handler, NULL, 'Drupal\Core\Validation\Annotation\Constraint');
$this->discovery = new StaticDiscoveryDecorator($this->discovery, array($this, 'registerDefinitions'));
$this->alterInfo('validation_constraint');
$this->setCacheBackend($cache_backend, 'validation_constraint_plugins');
......@@ -106,10 +106,7 @@ public function registerDefinitions() {
*/
public function processDefinition(&$definition, $plugin_id) {
// Make sure 'type' is set and either an array or FALSE.
if (!isset($definition['type'])) {
$definition['type'] = array();
}
elseif ($definition['type'] !== FALSE && !is_array($definition['type'])) {
if ($definition['type'] !== FALSE && !is_array($definition['type'])) {
$definition['type'] = array($definition['type']);
}
}
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\Core\Validation\Constraint\AllowedValuesConstraint.
* Contains \Drupal\Core\Validation\Plugin\Validation\Constraint\AllowedValuesConstraint.
*/
namespace Drupal\Core\Validation\Plugin\Validation\Constraint;
......@@ -12,7 +12,7 @@
/**
* Checks for the value being allowed.
*
* @Plugin(
* @Constraint(
* id = "AllowedValues",
* label = @Translation("Allowed values", context = "Validation")
* )
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\Core\Validation\Plugin\Validation\Constraint\CollectionConstraint.
* Contains \Drupal\Core\Validation\Plugin\Validation\Constraint\ComplexDataConstraint.
*/
namespace Drupal\Core\Validation\Plugin\Validation\Constraint;
......@@ -14,7 +14,7 @@
*
* Validates properties of complex data structures.
*
* @Plugin(
* @Constraint(
* id = "ComplexData",
* label = @Translation("Complex data", context = "Validation")
* )
......
......@@ -14,7 +14,7 @@
*
* Overrides the symfony constraint to use Drupal-style replacement patterns.
*
* @Plugin(
* @Constraint(
* id = "Count",
* label = @Translation("Count", context = "Validation"),
* type = { "list" }
......
......@@ -14,7 +14,7 @@
*
* Overrides the symfony constraint to use the strict setting.
*
* @Plugin(
* @Constraint(
* id = "Email",
* label = @Translation("Email", context = "Validation")
* )
......
......@@ -14,7 +14,7 @@
*
* Overrides the symfony constraint to handle empty Typed Data structures.
*
* @Plugin(
* @Constraint(
* id = "Null",
* label = @Translation("Null", context = "Validation"),
* type = false
......
......@@ -16,7 +16,7 @@
*
* @todo: Move this below the TypedData core component.
*
* @Plugin(
* @Constraint(
* id = "Length",
* label = @Translation("Length", context = "Validation"),
* type = { "string" }
......
......@@ -14,7 +14,7 @@
*
* Overrides the symfony constraint to handle empty Typed Data structures.
*
* @Plugin(
* @Constraint(
* id = "NotNull",
* label = @Translation("NotNull", context = "Validation"),
* type = false
......
......@@ -12,7 +12,7 @@
/**
* Supports validating all primitive types.
*
* @Plugin(
* @Constraint(
* id = "PrimitiveType",
* label = @Translation("Primitive type", context = "Validation")
* )
......
......@@ -16,7 +16,7 @@
*
* @todo: Move this below the TypedData core component.
*
* @Plugin(
* @Constraint(
* id = "Range",
* label = @Translation("Range", context = "Validation"),
* type = { "integer", "float" }
......
......@@ -12,7 +12,7 @@
/**
* Supports validating feed titles.
*
* @Plugin(
* @Constraint(
* id = "FeedTitle",
* label = @Translation("Feed title", context = "Validation")
* )
......
......@@ -12,7 +12,7 @@
/**
* Supports validating feed URLs.
*
* @Plugin(
* @Constraint(
* id = "FeedUrl",
* label = @Translation("Feed URL", context = "Validation")
* )
......
......@@ -12,7 +12,7 @@
/**
* Supports validating comment author names.
*
* @Plugin(
* @Constraint(
* id = "CommentName",
* label = @Translation("Comment author name", context = "Validation"),
* type = "entity:comment"
......
......@@ -12,7 +12,7 @@
/**
* Checks if a value is not equal.
*
* @Plugin(
* @Constraint(
* id = "TestField",
* label = @Translation("Test Field", context = "Validation"),
* type = { "integer" }
......
......@@ -12,7 +12,7 @@
/**
* Checks that the node is assigned only a "leaf" term in the forum taxonomy.
*
* @Plugin(
* @Constraint(
* id = "ForumLeaf",
* label = @Translation("Forum leaf", context = "Validation"),
* )
......
......@@ -12,7 +12,7 @@
/**
* Defines an access validation constraint for links.
*
* @Plugin(
* @Constraint(
* id = "LinkAccess",
* label = @Translation("Link URI can be accessed by the user.", context = "Validation"),
* )
......
......@@ -12,7 +12,7 @@
/**
* Defines a protocol validation constraint for links to external URLs.
*
* @Plugin(
* @Constraint(
* id = "LinkExternalProtocols",
* label = @Translation("No dangerous external protocols", context = "Validation"),
* )
......
......@@ -12,7 +12,7 @@
/**
* Defines a protocol validation constraint for links to broken internal URLs.
*
* @Plugin(
* @Constraint(
* id = "LinkNotExistingInternal",
* label = @Translation("No broken internal links", context = "Validation"),
* )
......
......@@ -15,7 +15,7 @@
/**
* Validation constraint for links receiving data allowed by its settings.
*
* @Plugin(
* @Constraint(
* id = "LinkType",
* label = @Translation("Link data valid for link type.", context = "Validation"),
* )
......
......@@ -1967,6 +1967,19 @@ function hook_config_schema_info_alter(&$definitions) {
$definitions['date_format']['form_element_class'] = '\Drupal\config_translation\FormElement\DateFormat';
}
/**
* Alter validation constraint plugin definitions.
*
* @param array[] $definitions
* The array of validation constraint definitions, keyed by plugin ID.
*
* @see \Drupal\Core\Validation\ConstraintManager
* @see \Drupal\Core\Validation\Annotation\Constraint
*/
function hook_validation_constraint_alter(array &$definitions) {
$definitions['Null']['class'] = '\Drupal\mymodule\Validator\Constraints\MyClass';
}
/**
* @} End of "addtogroup hooks".
*/
......
......@@ -12,7 +12,7 @@
/**
* Constraint with multiple fields.
*
* @Plugin(
* @Constraint(
* id = "EntityTestComposite",
* label = @Translation("Constraint with multiple fields."),
* type = "entity"
......
......@@ -12,7 +12,7 @@
/**
* Constraint on entity entity level.
*
* @Plugin(
* @Constraint(
* id = "EntityTestEntityLevel",
* label = @Translation("Constraint on the entity level."),
* type = "entity"
......
......@@ -11,7 +11,7 @@
/**
* Supports validating widget constraints.
*
* @Plugin(
* @Constraint(
* id = "FieldWidgetConstraint",
* label = @Translation("Field widget constraint.")
* )
......
......@@ -12,7 +12,7 @@
/**
* Checks if the plain text password is provided for editing a protected field.
*
* @Plugin(
* @Constraint(
* id = "ProtectedUserField",
* label = @Translation("Password required for protected field change", context = "Validation")
* )
......
......@@ -19,7 +19,7 @@
* and the user performing the edit has 'administer users' permission.
* This allows users without email address to be edited and deleted.
*
* @Plugin(
* @Constraint(
* id = "UserMailRequired",
* label = @Translation("User email required", context = "Validation")
* )
......
......@@ -12,7 +12,7 @@
/**
* Checks if a user's email address is unique on the site.
*
* @Plugin(
* @Constraint(
* id = "UserMailUnique",
* label = @Translation("User email unique", context = "Validation")
* )
......
......@@ -12,7 +12,7 @@
/**
* Checks if a value is a valid user name.
*
* @Plugin(
* @Constraint(
* id = "UserName",
* label = @Translation("User name", context = "Validation"),
* )
......
......@@ -12,7 +12,7 @@
/**
* Checks if a user name is unique on the site.
*
* @Plugin(
* @Constraint(
* id = "UserNameUnique",
* label = @Translation("User name unique", context = "Validation"),
* )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment