diff --git a/src/Controller/FieldList.php b/src/Controller/FieldList.php new file mode 100644 index 0000000..78e8bd1 --- /dev/null +++ b/src/Controller/FieldList.php @@ -0,0 +1,34 @@ +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); + } +} diff --git a/src/Form/LoggingSettingsForm.php b/src/Form/LoggingSettingsForm.php index f3de946..a295601 100644 --- a/src/Form/LoggingSettingsForm.php +++ b/src/Form/LoggingSettingsForm.php @@ -4,6 +4,7 @@ use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\field\Entity\FieldStorageConfig; /** * Configure UCEAP Logging settings. @@ -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.'), - '#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'] = [ @@ -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); diff --git a/uceap_logging.routing.yml b/uceap_logging.routing.yml index b361612..ddf293d 100644 --- a/uceap_logging.routing.yml +++ b/uceap_logging.routing.yml @@ -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' \ No newline at end of file