/Drupal 8

function hook_views_query_substitutions

hook_views_query_substitutions(ViewExecutable $view)

Replace special strings in the query before it is executed.

The idea is that certain dynamic values can be placed in a query when it is built, and substituted at run-time, allowing the query to be cached and still work correctly when executed.


\Drupal\views\ViewExecutable $view: The View being executed.

Return value

array An associative array where each key is a string to be replaced, and the corresponding value is its replacement. The strings to replace are often surrounded with '***', as illustrated in the example implementation, to avoid collisions with other values in the query.

Related topics

Define functions that alter the behavior of Drupal core.


core/modules/views/views.api.php, line 660
Describes hooks and plugins provided by the Views module.


function hook_views_query_substitutions(ViewExecutable $view) {
  // Example from views_views_query_substitutions().
  return array(
    '***CURRENT_VERSION***' => \Drupal::VERSION,
    '***LANGUAGE_language_content***' => \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId(),
    PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT => \Drupal::languageManager()->getDefaultLanguage()->getId(),

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.