Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/Controller/FieldList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Drupal\uceap_logging\Controller;

use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Drupal\field\Entity\FieldStorageConfig;

class FieldList extends ControllerBase {

public function autocomplete(Request $request) {
$string = $request->query->get('q');

$fields = \Drupal::entityTypeManager()
->getStorage('field_storage_config')
->loadMultiple();

$matches = [];

foreach ($fields as $field) {
$name = $field->getName();

if (stripos($name, $string) !== FALSE) {
$matches[] = [
'value' => $name,
'label' => $name,
];
}
}

return new JsonResponse($matches);
}
}
22 changes: 8 additions & 14 deletions src/Form/LoggingSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\field\Entity\FieldStorageConfig;

/**
* Configure UCEAP Logging settings.
Expand Down Expand Up @@ -31,11 +32,11 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('uceap_logging.settings');

$form['sensitive_fields'] = [
'#type' => 'textarea',
'#title' => $this->t('Sensitive Fields'),
'#description' => $this->t('Enter field machine names (one per line) that should have their values masked in entity change logs. When these fields are modified, they will appear in logs with masked values (e.g., ***MASKED***) instead of actual values.'),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description should be restored.

'#default_value' => implode("\n", $config->get('sensitive_fields') ?? []),
'#rows' => 10,
'#type' => 'textfield',
'#title' => $this->t('Select Field Machine Name'),
'#autocomplete_route_name' => 'uceap_logging.field_list',
'#multiple' => TRUE,
'#default_value' => implode(', ', $config->get('sensitive_fields')) ?? [],
];

$form['help'] = [
Expand Down Expand Up @@ -63,17 +64,10 @@ public function buildForm(array $form, FormStateInterface $form_state) {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Convert textarea input to array.
$sensitive_fields_raw = $form_state->getValue('sensitive_fields');
$sensitive_fields = array_filter(
array_map('trim', explode("\n", $sensitive_fields_raw)),
function ($field) {
return !empty($field);
}
);
$selectable_sensitive_fields_raw = explode(",", $form_state->getValue('sensitive_fields'));

$this->config('uceap_logging.settings')
->set('sensitive_fields', array_values($sensitive_fields))
->set('sensitive_fields', array_values($selectable_sensitive_fields_raw))
->save();

parent::submitForm($form, $form_state);
Expand Down
7 changes: 7 additions & 0 deletions uceap_logging.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ uceap_logging.settings:
_title: 'Logging Settings'
requirements:
_permission: 'administer site configuration'

uceap_logging.field_list:
path: '/field-list'
defaults:
_controller: '\Drupal\uceap_logging\Controller\FieldList::autocomplete'
requirements:
_permission: 'access content'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be administer site configuration