Commit 43a7432d authored by catch's avatar catch

Issue #2700405 by amateescu, vasike: User ref field includes the Anonymous...

Issue #2700405 by amateescu, vasike: User ref field includes the Anonymous user when 'include_anonymous' is set not to, when using select widget
parent 31f0c068
......@@ -332,6 +332,25 @@ public function testUserHandler() {
),
);
$this->assertReferenceable($selection_options, $referenceable_tests, 'User handler (does not include anonymous)');
// Check that the Anonymous user is not included in the results when no
// label matching is done, for example when using the 'options_select'
// widget.
$referenceable_tests = array(
array(
'arguments' => array(
array(NULL),
),
'result' => array(
'user' => array(
$users['admin']->id() => $user_labels['admin'],
$users['non_admin']->id() => $user_labels['non_admin'],
$users['blocked']->id() => $user_labels['blocked'],
),
),
),
);
$this->assertReferenceable($selection_options, $referenceable_tests, 'User handler (does not include anonymous)');
}
/**
......
......@@ -143,6 +143,13 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
*/
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = parent::buildEntityQuery($match, $match_operator);
$handler_settings = $this->configuration['handler_settings'];
// Filter out the Anonymous user if the selection handler is configured to
// exclude it.
if (isset($handler_settings['include_anonymous']) && !$handler_settings['include_anonymous']) {
$query->condition('uid', 0, '<>');
}
// The user entity doesn't have a label column.
if (isset($match)) {
......@@ -150,7 +157,6 @@ protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS')
}
// Filter by role.
$handler_settings = $this->configuration['handler_settings'];
if (!empty($handler_settings['filter']['role'])) {
$query->condition('roles', $handler_settings['filter']['role'], 'IN');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment