简体   繁体   English

Drupal 7视图:如何将一个视图重用于多个字段,或者如何让用户选择显示哪个字段视图?

[英]Drupal 7 Views : How to reuse one view for multiple fields OR how to let user select which field view displays?

My Task: I have content type which have 100+ different mostly numeric fields (big questionnaire for NGO with yearly reports). 我的任务:我的内容类型具有100多个不同的数字字段(针对具有年度报告的NGO的大型问卷调查)。 For one field I can use Views module to let user select which reports include (for example one year) and display it as nice graph (using for example Views+Charts). 对于一个字段,我可以使用“视图”模块让用户选择包括哪些报告(例如一年),并将其显示为漂亮的图形(例如使用“视图+图表”)。 I would have to define about 100+ nearly identical views, which differs only by what field data they use. 我将必须定义大约100多个几乎完全相同的视图,这些视图仅因它们使用的字段数据不同而不同。

My Question: Is there any way how to reuse one view definition and just change data from which field id display? 我的问题:有什么方法可以重用一个视图定义并仅更改显示哪个字段ID的数据?

Solutions so far: I found two not really good solutions: 到目前为止的解决方案:我发现了两个不太好的解决方案:

  • Create one view, export it (using Features or similar way) and then clone this export, rewrite field it uses as source and than add. 创建一个视图,将其导出(使用“功能”或类似方式),然后克隆此导出,重写它用作源并添加的字段。 But this just speed up creating one view for each 100+ fields. 但这只是加快了为每100多个字段创建一个视图的速度。
  • Use module Views Dynamic Fields - it allows user to select which fields to display. 使用模块查看动态字段 -它允许用户选择要显示的字段。 But I would still have separate definition how to display for each field, so not much better than add one view for each 100+ fields. 但是我仍然有单独的定义如何显示每个字段,因此,与为每100个以上字段添加一个视图相比,没有什么好得多的。

I suggest writing your own Views field display plugin! 我建议编写自己的“视图”字段显示插件! This is actually all documented within the Views module folder: views/docs/views.api.php. 实际上,所有这些都记录在“视图”模块文件夹中:views / docs / views.api.php。 Depending on your fields I'm not sure how you would exactly connect the data to the view. 根据您的字段,我不确定如何将数据准确连接到视图。

Another alternative would be to just use a PHP Code field, and figure out a way to programmatically display the data from the field you wanted. 另一种选择是仅使用PHP Code字段,并找到一种以编程方式显示所需字段中数据的方法。 The downside to this is that you wont be able to use that field to sort/search on with any filters as far as I know. 不利的一面是,据我所知,您将无法使用该字段对任何过滤器进行排序/搜索。

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

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