protected function FieldValidationRuleBase::updateSettings in Field Validation 8
Helper method to update configuration of ruleset.
Parameters
array $data: Data array to update.
string $ruleId: New rule id.
string $ruleTitle: New rule title.
\Drupal\field_validation\Entity\FieldValidationRuleSet $ruleSet: Check for ruleset specific constraint.
string $fieldName: Set the field.
string $error: Set the error message.
Return value
\Drupal\field_validation\Entity\FieldValidationRuleSet Returns new ruleset with updated settings.
Throws
\Drupal\Core\Entity\EntityStorageException
11 calls to FieldValidationRuleBase::updateSettings()
- DateRangeFieldValidationRuleTest::testInvalidDateRangeRule in tests/
src/ Kernel/ Plugin/ FieldValidationRule/ DateRangeFieldValidationRuleTest.php - Tests invalid date inputs.
- DateRangeFieldValidationRuleTest::testValidDateRangeRule in tests/
src/ Kernel/ Plugin/ FieldValidationRule/ DateRangeFieldValidationRuleTest.php - Tests valid date inputs.
- IpFieldValidationRuleTest::testInvalidIpRule in tests/
src/ Kernel/ Plugin/ FieldValidationRule/ IpFieldValidationRuleTest.php - Tests Invalid ip inputs.
- IpFieldValidationRuleTest::testMaloformedAndEmptyIp in tests/
src/ Kernel/ Plugin/ FieldValidationRule/ IpFieldValidationRuleTest.php - Tests empty and malformed input.
- IpFieldValidationRuleTest::testValidIpRule in tests/
src/ Kernel/ Plugin/ FieldValidationRule/ IpFieldValidationRuleTest.php - Tests valid ip inputs.
File
- tests/
src/ Kernel/ Plugin/ FieldValidationRule/ FieldValidationRuleBase.php, line 71
Class
- FieldValidationRuleBase
- FieldValidationRuleBase class.
Namespace
Drupal\Tests\field_validation\Kernel\Plugin\FieldValidationRuleCode
protected function updateSettings(array $data, string $ruleId, string $ruleTitle, FieldValidationRuleSet $ruleSet, string $fieldName, string $error = 'Something is wrong!') {
$fieldValidationRules = $ruleSet
->getFieldValidationRules();
foreach ($fieldValidationRules as $fieldValidationRule) {
$ruleSet
->deleteFieldValidationRule($fieldValidationRule);
}
$ruleSet
->addFieldValidationRule([
'id' => $ruleId,
'title' => $ruleTitle,
'weight' => 1,
'field_name' => $fieldName,
'column' => 'value',
'error_message' => $error,
'data' => $data,
]);
$ruleSet
->save();
return $ruleSet;
}