I call the view in the cron hook and use advancedRender to get the value on the field (with rewrite).
it works fine with the browser.
but when I call the cron with the command line I get an error
LogicException : Render context is empty, because render() was called outside of a renderRoot() or renderInIsolation() call. Use renderInIsolation()/renderRoot() or #lazy_builder/#pre_render instead. dans Drupal\Core\Render\Renderer->doRender() (ligne 303 de /var/www/drupal10/web/core/lib/Drupal/Core/Render/Renderer.php)
it comes from $this->getRenderer()->render($value) in public function advancedRender(ResultRow $values)
/**
* Implements hook_cron().
*/
function custom_cron() {
// Get the view.
$view = Views::getView('relance');
// Execute the view.
$view->execute($display_id);
$view->preview();
foreach ($view->result as $rid => $row) {
$message = $view->field['field_custom_message']->advancedRender($row)->__toString();
}
}
in core/modules/views/src/Plugin/views/field/FieldPluginBase.php
in line 1234, 1216, 1204
replace
$this->getRenderer()->render($value);
by
$this->getRenderer()->renderRoot($value); or
$this->getRenderer()->renderInIsolation($value);
Active
10.3 β¨
Last updated