Skip to content

Instantly share code, notes, and snippets.

/**
* Implements hook_views_pre_view().
*/
function cgap_search_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
$view->element['#cache']['contexts'] = ['url.path', 'url.query_args'];
}
// Is the current route/path the front page?
if ($is_front = \Drupal::service('path.matcher')->isFrontPage()) {}
// Need to know what the current page's requested path was, as opposed to the route? You can do this:
$current_uri = \Drupal::request()->getRequestUri();
// Need to redirect to a specific page?
use Drupal\Core\Controller\ControllerBase;
class MyControllerClass extends ControllerBase {