Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration option for whether to match blocked users (defaulting to FALSE) #34

Merged
merged 3 commits into from
Oct 2, 2024
Merged
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
1 change: 1 addition & 0 deletions config/install/civiremote.settings.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cmrf_connector: civiremote
acquire_civiremote_id: false
match_blocked_users: false
25 changes: 25 additions & 0 deletions config/schema/civiremote.schema.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
civiremote.settings:
type: config_object
mapping:
cmrf_connector:
type: string
label: 'CiviMRF Connector'
acquire_civiremote_id:
type: boolean
label: 'Acquire CiviRemote ID'
match_blocked_users:
type: boolean
label: 'Match blocked users'
match_contact_mapping:
type: sequence
label: 'Parameter mapping'
sequence:
type: mapping
label: 'Mapping of a Drupal user field to a CiviCRM contact field'
mapping:
user_field:
type: string
label: 'Drupal user field'
contact_field:
type: string
label: 'CiviCRM contact field'
action.configuration.civiremote_match_contact_action:
type: action_configuration_default
label: 'CiviRemote: Match contact(s)'
Expand Down
11 changes: 11 additions & 0 deletions src/Form/CiviRemoteConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#default_value' => $config->get('acquire_civiremote_id'),
];

$form['match_blocked_users'] = [
'#type' => 'checkbox',
'#title' => $this->t('Match blocked users'),
'#description' => $this->t('Whether to match blocked users to a CiviCRM contact. If unchecked, only active users will be matched.'),
'#default_value' => $config->get('match_blocked_users'),
'#states' => [
'visible' => [':input[name="acquire_civiremote_id"]' => ['checked' => TRUE]],
],
];

$form['match_contact_mapping'] = [
'#type' => 'fieldset',
'#title' => $this->t('Parameter mapping'),
Expand Down Expand Up @@ -198,6 +208,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('civiremote.settings');
$config->set('cmrf_connector', $form_state->getValue('cmrf_connector'));
$config->set('acquire_civiremote_id', $form_state->getValue('acquire_civiremote_id'));
$config->set('match_blocked_users', $form_state->getValue('match_blocked_users'));
$config->set('match_contact_mapping', $form_state->getValue('match_contact_mapping_table'));
$config->save();
parent::submitForm($form, $form_state);
Expand Down
5 changes: 5 additions & 0 deletions src/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public static function matchContact(UserInterface $user, $prefix = '') {
/* @var \Drupal\civiremote\CiviMRF $cmrf */
$cmrf = Drupal::service('civiremote.cmrf');
$config = Drupal::config('civiremote.settings');

// Only match locked users when configured.
if ($user->isBlocked() && !($config->get('match_blocked_users') ?? FALSE)) {
return;
}
$params = [];

// Use base URL as default key prefix.
Expand Down
Loading
Loading