RandomTextAnonymizer.php in General Data Protection Regulation 8
File
modules/anonymizer/src/Plugin/Anonymizer/RandomTextAnonymizer.php
View source
<?php
namespace Drupal\anonymizer\Plugin\Anonymizer;
use Drupal\anonymizer\Anonymizer\AnonymizerBase;
use Drupal\Core\Field\FieldItemListInterface;
class RandomTextAnonymizer extends AnonymizerBase {
public function anonymize($input, FieldItemListInterface $field = NULL) {
if (empty($input)) {
return $input;
}
$maxLength = NULL;
if (NULL !== $field) {
$maxLength = $field
->getDataDefinition()
->getSetting('max_length');
}
$value = 'anon_' . $this->faker
->generator()
->words(1, TRUE);
if ($maxLength !== NULL && \strlen($input) > $maxLength) {
$value = \substr(0, $maxLength);
}
return $value;
}
}