I’ve created my own custom module called “foobar_module” and in it, I’m trying to override an AJAX-driven exposed filter value that expects user target_ids. The reason I’m trying to do this is because I’m modifying the exposed filter to allow users to filter actual human names instead of target_ids of users.
To do all this, I’ve used HOOK_views_query_alter(&$view, &$query). It gives me access to everything I need except the
following object:
$query->where[1]['conditions'][3]['field']->conditions
…which turns out to be protected.
From what I can tell from other developers who experienced the same situation, they used &DatabaseCondition::conditions() to access the protected data structure. I tried to do this against my $query variable
like so:
$blah = $query->conditions();
dpm($blah);
…and with…
$blah = $query->where[1]['conditions'][3]['field']->conditions->conditions();
dpm($blah);
…both of which generate the following error:
An AJAX HTTP error occurred. HTTP Result Code: 200 Debugging
information follows. Path: /projects/foobar/views/ajax StatusText: OK
ResponseText: Fatal error: Cannot access protected property
DatabaseCondition::$conditions in
C:\www\projects\foobar\sites\all\modules\foobar_module\foobar_module.module
on line 33
The docs for &DatabaseCondition::conditions() found here indicate that the conditions() method should should be applied to a pass-by-reference variable. Since the HOOK I’m trying to execute from passes $query by reference, I’m not entirely sure what I’m doing wrong here… Maybe the docs are completely wrong now?
Long story short, I just need to modify $query->where[1][‘conditions’][3][‘field’]->conditions to change what gets submitted to replace the human names with the target_ids of the users the names match against via a query I used on the side for searching for users (which returns target_ids of those found).
Apparently viewing protected variables isn’t a problem. By using print_r, I can at least see what’s in this protected variable:
Array
(
[0] => Array
(
[field] => node.status
[value] => 1
[operator] => =
)
[1] => Array
(
[field] => node.type
[value] => Array
(
[0] => foobar_page
)
[operator] => in
)
[2] => Array
(
[field] => node.title
[value] => blah
[operator] => NOT LIKE
)
[3] => Array
(
[field] => DatabaseCondition Object
(
[conditions:protected] => Array
(
[#conjunction] => OR
[0] => Array
(
[field] => CONCAT_WS(' ', node.title, ' ', field_data_field_foobar_value, ' ', field_data_field_foobar_ppl.field_data_field_foobar_ppl_target_id) LIKE :views_combine
[value] => Array
(
[:views_combine] => %Don%
)
[operator] =>
)
[1] => Array
(
[field] => CONCAT_WS(' ', node.title, ' ', field_data_field_foobar_value, ' ', field_data_field_foobar_ppl.field_data_field_foobar_ppl_target_id) LIKE :views_combine1
[value] => Array
(
[:views_combine1] => %Jill%
)
[operator] =>
)
)
[arguments:protected] => Array
(
)
[changed:protected] => 1
[queryPlaceholderIdentifier:protected] =>
)
[value] =>
[operator] =>
)
)
I’m thinking that a method surely exists to modify these values… So I’m hoping that someone out there has an answer…
Thoughts? I’ve posted about this in some other forums, so if I get any good leads from them, I’ll update this with the answer.
(Thanks in advance.)