public function GDPRController::fieldsList in General Data Protection Regulation 8
Same name and namespace in other branches
- 8.2 modules/gdpr_fields/src/Controller/GDPRController.php \Drupal\gdpr_fields\Controller\GDPRController::fieldsList()
- 3.0.x modules/gdpr_fields/src/Controller/GDPRController.php \Drupal\gdpr_fields\Controller\GDPRController::fieldsList()
Lists all fields with GDPR sensitivity.
Return value
array The Views plugins report page.
1 string reference to 'GDPRController::fieldsList'
- gdpr_fields.routing.yml in modules/
gdpr_fields/ gdpr_fields.routing.yml - modules/gdpr_fields/gdpr_fields.routing.yml
File
- modules/
gdpr_fields/ src/ Controller/ GDPRController.php, line 63
Class
- GDPRController
- Returns responses for GDPR Field routes.
Namespace
Drupal\gdpr_fields\ControllerCode
public function fieldsList() {
$filters = GdprFieldFilterForm::getFilters($this->request);
$output = [];
$output['filter'] = $this
->formBuilder()
->getForm('Drupal\\gdpr_fields\\Form\\GdprFieldFilterForm');
$output['#attached']['library'][] = 'gdpr_fields/field-list';
foreach ($this
->entityTypeManager()
->getDefinitions() as $entity_type_id => $definition) {
// Skip non-fieldable/config entities.
if (!$definition
->entityClassImplements(FieldableEntityInterface::class)) {
continue;
}
// If a filter is active, exclude any entities that don't match.
if (!empty($filters['entity_type']) && !in_array($entity_type_id, $filters['entity_type'])) {
continue;
}
$bundles = $this->collector
->getBundles($entity_type_id);
$output[$entity_type_id] = [
'#type' => 'details',
'#title' => $definition
->getLabel() . " [{$entity_type_id}]",
'#open' => TRUE,
];
if (count($bundles) > 1) {
$at_least_one_bundle_has_fields = FALSE;
foreach ($bundles as $bundle_id => $bundle_info) {
$field_table = $this
->buildFieldTable($definition, $bundle_id, $filters);
if ($field_table) {
$at_least_one_bundle_has_fields = TRUE;
$output[$entity_type_id][$bundle_id] = [
'#type' => 'details',
'#title' => new TranslatableMarkup('%label [%bundle]', [
'%label' => $bundle_info['label'],
'%bundle' => $bundle_id,
]),
'#open' => TRUE,
];
$output[$entity_type_id][$bundle_id]['fields'] = $field_table;
}
}
if (!$at_least_one_bundle_has_fields) {
unset($output[$entity_type_id]);
}
}
else {
// Don't add another collapsible wrapper around single bundle entities.
$bundle_id = $entity_type_id;
$field_table = $this
->buildFieldTable($definition, $bundle_id, $filters);
if ($field_table) {
$output[$entity_type_id][$bundle_id]['fields'] = $field_table;
}
else {
// If the entity has no fields because they've been filtered out
// don't bother including it.
unset($output[$entity_type_id]);
}
}
}
return $output;
}