Created
February 7, 2017 07:59
-
-
Save stborchert/d5b88ccaaa7f1c1e9ea728d84be80174 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_views_pre_build(). | |
*/ | |
function dingens_search_views_pre_build(ViewExecutable $view) { | |
$functions = []; | |
$functions[] = sprintf('dingens_search_views__%s__pre_build', $view->id()); | |
$functions[] = sprintf('dingens_search_views__%s_%s__pre_build', $view->id(), $view->current_display); | |
foreach ($functions as $callback) { | |
if (is_callable($callback)) { | |
call_user_func_array($callback, [$view]); | |
} | |
} | |
} | |
/** | |
* Implements hook_views_pre_build() on behalf of view | |
* landingpage:landingpage__legacy_push_child. | |
*/ | |
function dingens_search_views__landingpage_landingpage__legacy_push_child__pre_build(ViewExecutable $view) { | |
$arguments = \Drupal::state()->get('dingens_search:landingpage:arguments', []); | |
if (!empty($arguments[$view->args[0]])) { | |
$view->args[1] = $arguments[$view->args[0]]; | |
} | |
} | |
/** | |
* Implements hook_views_pre_render(). | |
*/ | |
function dingens_search_views_pre_render(ViewExecutable $view) { | |
$functions = []; | |
$functions[] = sprintf('dingens_search_views__%s__pre_build', $view->id()); | |
$functions[] = sprintf('dingens_search_views__%s_%s__pre_build', $view->id(), $view->current_display); | |
foreach ($functions as $callback) { | |
if (is_callable($callback)) { | |
call_user_func_array($callback, [$view]); | |
} | |
} | |
} | |
/** | |
* Implements hook_views_pre_render() on behalf of view | |
* landingpage:landingpage_keyword. | |
*/ | |
function dingens_search_views__landingpage_landingpage_keyword__pre_render(ViewExecutable $view) { | |
$arguments = \Drupal::state()->get('dingens_search:landingpage:arguments', []); | |
// Update argument with results. | |
$nids = []; | |
foreach ($view->result as $row) { | |
$nids[] = $row->{'entity:node/nid'}[0]; | |
} | |
if (isset($view->args[1]) && 'all' === $view->args[1]) { | |
$arguments[$view->args[0]] = implode(',', $nids); | |
\Drupal::state()->set('dingens_search:landingpage:arguments', $arguments); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment