- Issue created by @jelle_s
As of right now, there are plugins for all field types, but in \Drupal\entity_sanitizer\Sanitizer.php
the field types are still hardcoded.
To me personally it would make more sense to remove the switch case and just try to find a plugin for the field type. If no plugin is found, either return an empty array (as is done for the types that are deemed not to contain any sensitive info) or throw the UnsupportedFieldTypeException. If we would opt for the latter, we should create field sanitizer plugins for the hardcoded field types that now return an empty array. Basically the entire getValuesForField method could be simplified to:
protected function getValuesForField(string $table_name, string $field_name, string $field_type, FieldStorageDefinitionInterface $definition): array {
$fields = [];
try {
// Get the whitelist configuration.
$configurations = $this->configFactory->get('entity_sanitizer.whitelist')->get('configuration');
$columns = $definition->getColumns();
$fields = $this->fieldSanitizerManager
->createInstance($field_type, $configurations ?? [])
->getFieldValues($table_name, $field_name, $columns);
}
catch (PluginNotFoundException $e) {
throw new UnsupportedFieldTypeException($field_type, $field_name);
// or $fields = [];
}
return $fields;
}
If we do this we allow config to create their own plugins to sanitize their values.
Active
2.0
Code