0001-repatched-entityrefeerence-module.patch 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. From 1f82c4ef9b474a12d160813f767128d645f524cc Mon Sep 17 00:00:00 2001
  2. From: Bachir Soussi Chiadmi <bachir@g-u-i.me>
  3. Date: Sun, 19 Apr 2015 21:04:36 +0200
  4. Subject: [PATCH] repatched entityrefeerence module
  5. ---
  6. ...ityReference_SelectionHandler_Generic.class.php | 43 +++++++++++++++++++---
  7. 1 file changed, 38 insertions(+), 5 deletions(-)
  8. diff --git a/sites/all/modules/contrib/fields/entityreference/plugins/selection/EntityReference_SelectionHandler_Generic.class.php b/sites/all/modules/contrib/fields/entityreference/plugins/selection/EntityReference_SelectionHandler_Generic.class.php
  9. index 444a74c..660fe3d 100644
  10. --- a/sites/all/modules/contrib/fields/entityreference/plugins/selection/EntityReference_SelectionHandler_Generic.class.php
  11. +++ b/sites/all/modules/contrib/fields/entityreference/plugins/selection/EntityReference_SelectionHandler_Generic.class.php
  12. @@ -370,6 +370,28 @@ class EntityReference_SelectionHandler_Generic_node extends EntityReference_Sele
  13. * This only exists to workaround core bugs.
  14. */
  15. class EntityReference_SelectionHandler_Generic_user extends EntityReference_SelectionHandler_Generic {
  16. +
  17. + /**
  18. + * Implements EntityReferenceHandler::settingsForm().
  19. + */
  20. + public static function settingsForm($field, $instance) {
  21. + $settings = $field['settings']['handler_settings'];
  22. + $form = parent::settingsForm($field, $instance);
  23. + $form['referenceable_roles'] = array(
  24. + '#type' => 'checkboxes',
  25. + '#title' => t('User roles that can be referenced'),
  26. + '#default_value' => isset($settings['referenceable_roles']) ? array_filter($settings['referenceable_roles']) : array(),
  27. + '#options' => user_roles(TRUE),
  28. + );
  29. + $form['referenceable_status'] = array(
  30. + '#type' => 'checkboxes',
  31. + '#title' => t('User status that can be referenced'),
  32. + '#default_value' => isset($settings['referenceable_status']) ? array_filter($settings['referenceable_status']) : array('active' => 'active'),
  33. + '#options' => array('active' => t('Active'), 'blocked' => t('Blocked')),
  34. + );
  35. + return $form;
  36. + }
  37. +
  38. public function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') {
  39. $query = parent::buildEntityFieldQuery($match, $match_operator);
  40. @@ -378,11 +400,22 @@ class EntityReference_SelectionHandler_Generic_user extends EntityReference_Sele
  41. $query->propertyCondition('name', $match, $match_operator);
  42. }
  43. - // Adding the 'user_access' tag is sadly insufficient for users: core
  44. - // requires us to also know about the concept of 'blocked' and
  45. - // 'active'.
  46. - if (!user_access('administer users')) {
  47. - $query->propertyCondition('status', 1);
  48. + $field = $this->field;
  49. + $settings = $field['settings']['handler_settings'];
  50. + $referenceable_roles = isset($settings['referenceable_roles']) ? array_filter($settings['referenceable_roles']) : array();
  51. + $referenceable_status = isset($settings['referenceable_status']) ? array_filter($settings['referenceable_status']) : array('active' => 'active');
  52. +
  53. + // If this filter is not filled, use the users access permissions.
  54. + if (empty($referenceable_status)) {
  55. + // Adding the 'user_access' tag is sadly insufficient for users: core
  56. + // requires us to also know about the concept of 'blocked' and 'active'.
  57. + if (!user_access('administer users')) {
  58. + $query->propertyCondition('status', 1);
  59. + }
  60. + }
  61. + elseif (count($referenceable_status) == 1) {
  62. + $values = array('active' => 1, 'blocked' => 0);
  63. + $query->propertyCondition('status', $values[key($referenceable_status)]);
  64. }
  65. return $query;
  66. }
  67. --
  68. 2.3.5