Is there an out-of-the-box solution for printing the query of an entity query in Drupal 8?
Right now I’m using kind of a hack, adding:
->addTag('debug')
and then in a custom module:
function mymodule_query_alter($query) { if ($query->hasTag('debug')) { mymodule_query_debug($query); } }
and then the debug function:
function mymodule_query_debug($query) { $sql = (string) $query; $quoted = array(); foreach ((array) $query->arguments() as $key => $val) { if (is_array($val)) { $val = implode(', ',$val); } $quoted[$key] = Drupal::database()->quote($val); } $sql = strtr($sql, $quoted); $sql = str_replace('}', '', $sql); $sql = str_replace('{', '', $sql); print_r($sql); die(); }
Sponsored by SupremePR