You are here

function field_validation_entity_bundle_field_info_alter in Field Validation 8

@file field validation.

File

./field_validation.module, line 9
field validation.

Code

function field_validation_entity_bundle_field_info_alter(&$fields, EntityTypeInterface $entity_type, $bundle) {
  $ruleset_name = $entity_type
    ->id() . '_' . $bundle;
  $ruleset = \Drupal::entityTypeManager()
    ->getStorage('field_validation_rule_set')
    ->load($ruleset_name);
  if ($ruleset) {
    foreach ($fields as $field) {
      $field
        ->addConstraint('FieldValidationConstraint', [
        'ruleset_name' => $ruleset_name,
        'rule_uuid' => '',
      ]);
    }

    /*
        $rules = $ruleset->getFieldValidationRules();
        foreach ($rules as $field_validation_rule) {
      $field_name = $field_validation_rule->getFieldName();
      if(isset($fields[$field_name])){
          $fields[$field_name]->addConstraint('FieldValidationConstraint', [
            'ruleset_name' => $ruleset_name,
            'rule_uuid' =>$field_validation_rule->getUuid(),
          ]);
      }
        }
    */
  }
}