Is it possible to conditionally include nodes in a view based on the paths specified in a field on that node? The idea is to essentially mimic the default property of blocks, making their display allowed or disallowed at specified paths. My view (technically a view block) is being used to show sponsor images as a slideshow, and I'd like to be able to define which pages each specific sponsors' graphics should display.
I'd imagine it would include the use of a contextual filter on the field containing the paths, but I can't figure out how it would work. Possibly via some implementation of Views Argument Substitutions, although that seems to base its results off of specified path arguments and not the whole path. In the meantime, I'm implementing Nodeblock as a partial substitute, but I'd prefer to leverage views if possible.
EDIT: Thanks to mchar's answer below, I was able to get a working snippet for this functionality. It could probably be optimized, but that's for another thread.
function MYMODULE_views_pre_render(&$view) {
if($view->name=='sponsors') {
$current_path = drupal_lookup_path('alias',current_path());
foreach($view->result as $row_num => $row) {
foreach($row->field_field_urls_to_show_up_on as $urlNum => $url) {
$this_path = $url['rendered']['#markup'];
// If the path contains an asterisk
// Asterisks should only appear at the end of a path at the time of writing
if (strpos($haystack = $this_path, $needle = '*') !== false) {
$this_path = str_replace('/*', '', $this_path);
if (strpos($haystack = $current_path, $needle = $this_path) === false) {
unset($view->result[$row_num]);
}
}
// if current_path is not the same as the provided path (no *)
elseif ($current_path != $this_path) {
unset($view->result[$row_num]);
}
}
}
}
}
The idea is to essentially mimic the default property of blocks, making their display allowed or disallowed at specified paths.
If you create a view block it will be listed in blocks management and you can specify paths for them too, just like regular blocks.