我正在执行实体引用以从特定内容下获取节点。我正在寻找如何渲染刚刚创建到region.html.twig
模板中的实体引用函数的方法。以下是我当前正在处理的代码的一个片段
// Page region level pre-processing
function iom_preprocess_region(&$variables) {
if ($node = \Drupal::routeMatch()->getParameter('node')) {
$variables['content_type'] = $node->bundle();
}
$elements = $variables['elements'];
if (array_key_exists('#entity', $elements)) {
$region = $elements['#region'];
$entity = $elements['#entity'];
$bundle = _overrideBundle($entity->bundle());
preprocess($region, 'region', $entity, $variables);
preprocess($region."_{$bundle}", 'region', $entity, $variables);
}
}
function _preprocess_country_regional_offices_node($entity, &$variables) {
$entityStorage = \Drupal::service('entity_type.manager')->getStorage('node');
$regionalOffices = \Drupal::service('entity.query')
->get('node')
->condition('status', 1, '=')
->condition('type', 'regional_office')
->condition('field_primary_offices', '1')
->sort('created', 'DESC')
->execute();
$regionalOfficeEntities = $entityStorage->loadMultiple($regionalOffices);
$variables['regional_office'] = $regionalOfficeEntities;
}
答案 0 :(得分:1)
我可能会使用暴露的块来执行此操作,但是如果出于特定原因需要在代码中执行此操作。
actorOf