Same name and namespace in other branches
  1. 9.1.x core/lib/Drupal/Core/Validation/ConstraintManager.php \Drupal\Core\Validation\ConstraintManager::create()
  2. 9.0.x core/lib/Drupal/Core/Validation/ConstraintManager.php \Drupal\Core\Validation\ConstraintManager::create()
  3. 9.2.x core/lib/Drupal/Core/Validation/ConstraintManager.php \Drupal\Core\Validation\ConstraintManager::create()
  4. 8.9.x core/lib/Drupal/Core/Validation/ConstraintManager.php \Drupal\Core\Validation\ConstraintManager::create()
  5. 8.0.x core/lib/Drupal/Core/Validation/ConstraintManager.php \Drupal\Core\Validation\ConstraintManager::create()
  6. 8.2.x core/lib/Drupal/Core/Validation/ConstraintManager.php \Drupal\Core\Validation\ConstraintManager::create()
  7. 8.3.x core/lib/Drupal/Core/Validation/ConstraintManager.php \Drupal\Core\Validation\ConstraintManager::create()
  8. 8.4.x core/lib/Drupal/Core/Validation/ConstraintManager.php \Drupal\Core\Validation\ConstraintManager::create()
  9. 8.5.x core/lib/Drupal/Core/Validation/ConstraintManager.php \Drupal\Core\Validation\ConstraintManager::create()
  10. 8.6.x core/lib/Drupal/Core/Validation/ConstraintManager.php \Drupal\Core\Validation\ConstraintManager::create()
  11. 8.7.x core/lib/Drupal/Core/Validation/ConstraintManager.php \Drupal\Core\Validation\ConstraintManager::create()
  12. 8.8.x core/lib/Drupal/Core/Validation/ConstraintManager.php \Drupal\Core\Validation\ConstraintManager::create()

Creates a validation constraint.

Parameters

string $name: The name or plugin id of the constraint.

mixed $options: The options to pass to the constraint class. Required and supported options depend on the constraint class.

Return value

\Symfony\Component\Validator\Constraint A validation constraint plugin.

File

core/lib/Drupal/Core/Validation/ConstraintManager.php, line 72

Class

ConstraintManager
Constraint plugin manager.

Namespace

Drupal\Core\Validation

Code

public function create($name, $options) {
  if (!is_array($options)) {

    // Plugins need an array as configuration, so make sure we have one.
    // The constraint classes support passing the options as part of the
    // 'value' key also.
    $options = isset($options) ? array(
      'value' => $options,
    ) : array();
  }
  return $this
    ->createInstance($name, $options);
}