function gdpr_tasks_collect_rtf_data in General Data Protection Regulation 7
Collect RTF data for a specific user.
2 calls to gdpr_tasks_collect_rtf_data()
- Anonymizer::run in modules/
gdpr_tasks/ src/ Anonymizer.php - Runs anonymization routines against a user.
- gdpr_task_edit_gdpr_remove_form in modules/
gdpr_tasks/ gdpr_tasks.admin.inc - Form callback for removal tasks.
File
- modules/
gdpr_tasks/ gdpr_tasks.module, line 572 - Module file for the GDPR Tasks module.
Code
function gdpr_tasks_collect_rtf_data($user, $include_plugins = FALSE) {
ctools_include('plugins');
ctools_include('export');
$plugins = ctools_export_load_object('gdpr_fields_field_data');
$fields = array();
$gdpr_entities = gdpr_fields_collect_gdpr_entities('user', $user);
foreach ($gdpr_entities as $entity_type => $entities) {
foreach ($entities as $entity) {
$wrapper = entity_metadata_wrapper($entity_type, $entity);
foreach ($wrapper
->getPropertyInfo() as $property => $property_info) {
$entity_id = $wrapper
->getIdentifier();
$plugin_name = "{$entity_type}|{$wrapper->getBundle()}|{$property}";
if (isset($plugins[$plugin_name])) {
$field_config = $plugins[$plugin_name];
/* @var GDPRFieldData $field_config */
$allowed_values = array(
'anonymise',
'remove',
'maybe',
);
if ($field_config->disabled || !in_array($field_config
->getSetting('gdpr_fields_rtf'), $allowed_values)) {
continue;
}
if ($field_config
->getSetting('gdpr_fields_rtf')) {
// Figure out what to do based on the type.
$type = isset($property_info['type']) ? $property_info['type'] : 'string';
$is_list = substr($type, 0, 5) == 'list<';
if ($is_list) {
$type = entity_property_extract_innermost_type($type);
}
// Check if the type is an entity, except for files.
if ($type != 'file' && ($type == 'entity' || entity_get_info($type))) {
$type = 'entity';
}
// If this is a list, loop over getting the output.
$values = array();
if ($is_list) {
foreach ($wrapper->{$property} as $value) {
$values[] = gdpr_tasks_collect_rtf_data_extract_value($type, $value);
}
}
else {
$values[] = gdpr_tasks_collect_rtf_data_extract_value($type, $wrapper->{$property});
}
$data = array(
'label' => $field_config
->getSetting('label'),
'value' => implode(', ', array_filter($values)),
'notes' => $field_config
->getSetting('notes'),
'rtf' => $field_config
->getSetting('gdpr_fields_rtf'),
);
// If entity ID is being removed display as deletion.
if ($data['rtf'] == 'remove' && Anonymizer::propertyIsEntityId($field_config->entity_type, $field_config->property_name)) {
$data['rtf'] = 'delete entire entity';
}
if ($include_plugins) {
$data['plugin'] = $field_config;
$data['entity_type'] = $entity_type;
$data['entity_id'] = $entity_id;
$data['entity'] = $entity;
}
$fields["{$plugin_name}|{$entity_id}"] = $data;
}
}
}
}
}
return $fields;
}