repatched entityrefeerence module
This commit is contained in:
parent
c0af9037e9
commit
1f82c4ef9b
@ -370,6 +370,28 @@ class EntityReference_SelectionHandler_Generic_node extends EntityReference_Sele
|
||||
* This only exists to workaround core bugs.
|
||||
*/
|
||||
class EntityReference_SelectionHandler_Generic_user extends EntityReference_SelectionHandler_Generic {
|
||||
|
||||
/**
|
||||
* Implements EntityReferenceHandler::settingsForm().
|
||||
*/
|
||||
public static function settingsForm($field, $instance) {
|
||||
$settings = $field['settings']['handler_settings'];
|
||||
$form = parent::settingsForm($field, $instance);
|
||||
$form['referenceable_roles'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('User roles that can be referenced'),
|
||||
'#default_value' => isset($settings['referenceable_roles']) ? array_filter($settings['referenceable_roles']) : array(),
|
||||
'#options' => user_roles(TRUE),
|
||||
);
|
||||
$form['referenceable_status'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('User status that can be referenced'),
|
||||
'#default_value' => isset($settings['referenceable_status']) ? array_filter($settings['referenceable_status']) : array('active' => 'active'),
|
||||
'#options' => array('active' => t('Active'), 'blocked' => t('Blocked')),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
public function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') {
|
||||
$query = parent::buildEntityFieldQuery($match, $match_operator);
|
||||
|
||||
@ -378,11 +400,22 @@ class EntityReference_SelectionHandler_Generic_user extends EntityReference_Sele
|
||||
$query->propertyCondition('name', $match, $match_operator);
|
||||
}
|
||||
|
||||
// Adding the 'user_access' tag is sadly insufficient for users: core
|
||||
// requires us to also know about the concept of 'blocked' and
|
||||
// 'active'.
|
||||
if (!user_access('administer users')) {
|
||||
$query->propertyCondition('status', 1);
|
||||
$field = $this->field;
|
||||
$settings = $field['settings']['handler_settings'];
|
||||
$referenceable_roles = isset($settings['referenceable_roles']) ? array_filter($settings['referenceable_roles']) : array();
|
||||
$referenceable_status = isset($settings['referenceable_status']) ? array_filter($settings['referenceable_status']) : array('active' => 'active');
|
||||
|
||||
// If this filter is not filled, use the users access permissions.
|
||||
if (empty($referenceable_status)) {
|
||||
// Adding the 'user_access' tag is sadly insufficient for users: core
|
||||
// requires us to also know about the concept of 'blocked' and 'active'.
|
||||
if (!user_access('administer users')) {
|
||||
$query->propertyCondition('status', 1);
|
||||
}
|
||||
}
|
||||
elseif (count($referenceable_status) == 1) {
|
||||
$values = array('active' => 1, 'blocked' => 0);
|
||||
$query->propertyCondition('status', $values[key($referenceable_status)]);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user