You are here

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

Same name and namespace in other branches
  1. 8.2 src/Plugin/DataType/GranularityStringData.php \Drupal\duration_field\Plugin\DataType\GranularityStringData::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/GranularityStringData.php, line 35

Class

GranularityStringData
Provides the Granularity String typed data object.

Namespace

Drupal\duration_field\Plugin\DataType

Code

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

  // Add constraint to ensure that submitted data is a granularity string.
  $constraints[] = $constraint_manager
    ->create('granularity_string', []);
  return $constraints;
}