I am interested in altering a views query similar to: https://api.drupal.org/api/drupal/core%21modules%21views%21views.api.php..., but I'm unable to access the $query->where property as it's protected. Would it be possible to match the core "Sql" class, and make the "where" property public so this can be altered, or is there a reason for not allowing this outside of the class?
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 2799497-7-public-where-condition.patch | 454 bytes | guaneagler |
| #2 | 2799497-2--views_query_get_where.patch | 1.1 KB | drunken monkey |
Comments
Comment #2
drunken monkeyIt would be possible, yes, but we don't do it due to general best practices for OOP programming. Views is, sadly, a very bad example for that.
However, it is true that not being able to alter the
$whereproperty is a glaring hole in our API. The proper way to fix it, though, is to provide a getter. (Even cleaner would probably be a getter and a setter, but this should be simpler to use, and we don't need to be unnecessarily strict.)Thanks for the suggestion, and please try the attached patch!
Comment #3
borisson_Looks good!
Comment #5
drunken monkeyThanks for reviewing!
Committed.
Comment #7
guaneagler commentedSorry, I really want to change the query condition in hook_views_query_alter(), and the protected $where condition prevent me to do this. Just path for those have the same request.
Comment #8
sonnykt@guaneagler you can use the getter:
and just modify the
$whereobject.