简体   繁体   English

我们如何访问在Drupal 8中由内容类型的字段引用的视图中的段落字段

[英]How can we access the fields of a paragraph in views which is referred by a field of a content type in Drupal 8

I have a content type whose one field refers to a paragraph. 我有一个内容类型,其一个字段引用一个段落。 This paragraph is having title and description. 本段具有标题和描述。 I have given the option of adding as many paragraphs as they want in a content type. 我可以选择在内容类型中添加任意数量的段落。 I am looking for an option to get all the titles of the created paragraphs in views in Drupal 8 我正在寻找一个选项来在Drupal 8的视图中获取创建的段落的所有标题

view_pre_render hook for access the content type field in drupal 8. view_pre_render挂钩,用于访问Drupal 8中的内容类型字段。

function MODULENAME/THEMENAME_views_pre_render(\Drupal\views\ViewExecutable $view) {
  if ($view->id() == "viewname" && $view->current_display == 'view_machine_name') {
    foreach($view->result as $value){
      $field_value = strip_tags($value->_entity->get('field_name')->value);
      $value->_entity->set('field_name', $field_value);
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM