public function ConfigurableTrait::configErrors in Backup and Migrate 5.0.x
Get any validation errors in the config.
Parameters
array $params:
Return value
array
File
- src/
Core/ Config/ ConfigurableTrait.php, line 118
Class
- ConfigurableTrait
- A configurable object. Manages injection and access to a config object.
Namespace
Drupal\backup_migrate\Core\ConfigCode
public function configErrors(array $params = []) {
$out = [];
// Do some basic validation based on length and regex matching.
$schema = $this
->configSchema($params);
if (!empty($schema)) {
// Check each specified field.
foreach ($schema['fields'] as $key => $field) {
$value = $this
->confGet($key);
// Check if it's required.
if (!empty($field['required']) && empty($value)) {
$out[] = new ValidationError($key, $this
->t('%title is required.'), [
'%title' => $field['title'],
]);
}
// Check it for length.
if (!empty($field['min_length']) && strlen($value) < $field['min_length']) {
$out[] = new ValidationError($key, $this
->t('%title must be at least %count characters.'), [
'%title' => $field['title'],
'%count' => $field['min_length'],
]);
}
if (!empty($field['max_length']) && strlen($value) > $field['max_length']) {
$out[] = new ValidationError($key, $this
->t('%title must be at no more than %count characters.'), [
'%title' => $field['title'],
'%count' => $field['max_length'],
]);
}
// Check for the regular expression match.
if (!empty($field['must_match']) && !preg_match($field['must_match'], $value)) {
if (!empty($field['must_match_error'])) {
$out[] = new ValidationError($key, $field['must_match_error'], [
'%title' => $field['title'],
]);
}
else {
$out[] = new ValidationError($key, $this
->t('%title contains invalid characters.'), [
'%title' => $field['title'],
]);
}
}
}
}
return $out;
}