You are here

public function DateIntervalData::getConstraints in Duration Field 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/DataType/DateIntervalData.php \Drupal\duration_field\Plugin\DataType\DateIntervalData::getConstraints()

Gets a list of validation constraints.

Return value

array Array of constraints, each being an instance of \Symfony\Component\Validator\Constraint.

Overrides TypedData::getConstraints

File

src/Plugin/DataType/DateIntervalData.php, line 51

Class

DateIntervalData
Provides the Date Interval data type.

Namespace

Drupal\duration_field\Plugin\DataType

Code

public function getConstraints() {
  $constraint_manager = \Drupal::typedDataManager()
    ->getValidationConstraintManager();
  $constraints = parent::getConstraints();

  // Add a constraint to ensure that submitted data is valid for a PHP
  // DateInterval object.
  $constraints[] = $constraint_manager
    ->create('php_date_interval', []);
  return $constraints;
}