正在将站点从 Drupal 8 更新到 9,并在站点的 .theme 文件中遇到此错误:
错误:调用数组上的成员函数 view()
这是为 Drupal 7/8 编写的原始数组:
// ORIGINAL Capture viewable blocks and their settings to $build for Drupal 8
$build = array();
foreach ($blocks as $key => $block) {
if ($block->access('view')) {
$build[$key] = entity_view($block, 'block');
}
}
我用它来更新 entity_view 函数:https ://www.drupal.org/node/3033656
更新:如果这对其他人有帮助,则以下内容有效。
// Capture viewable blocks and their settings to $build
$build = array();
foreach ($blocks as $key => $block) {
if ($block->access('view')) {
$builder = \Drupal::entityTypeManager()->getViewBuilder('block');
$build[$key] = $builder->view($block, 'block');
}
}