Drupal:在视图中使用查询字符串数据
我在我的 drupal 网站上有多个版主角色。具有此角色的用户可以创建称为新闻的特定内容类型的内容。让我们将角色称为以下角色:role_a、role_b、role_c...
现在我有一个显示最后 5 个新闻元素的视图。
我的问题是如何根据查询字符串对视图中的新闻元素进行粒度化? 我的意思是在页面 http://mysite.com/a 上我只想查看由具有“a”角色的用户。 http://mysite.com/b 适用于“b”角色的用户。等等,
我如何在视图过滤器中使用查询字符串参数?
i have several moderator roles in my drupal site. the users with this roles can create content of specific content-type called News. let's call the roles the following: role_a, role_b, role_c, ...
now i have a View that shows the last 5 News elements.
my question is how to granulate the News elements in View according to the query string?
i mean on page http://mysite.com/a i want to see only the news that was added by the user with the "a" role. http://mysite.com/b is for the "b"-roled user. etc.
how can i use the query string parameters in the Views filter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你的意思是你想使用参数,而不是查询字符串。无论如何,我认为 Views 默认情况下不能处理角色名(它可以很好地处理角色 ID),因此您必须修改视图查询才能实现您想要的效果。
首先,将 User: Roles 添加为视图中的参数。然后,在自定义模块中,实现 hook_views_query_alter() 并通过将角色名替换为其角色 ID 来修改查询。
因此,例如,如果您的网址是 http://mysite.com/a,那么它将查找角色“a”的 ID,然后查找具有该角色的作者的所有节点。它还将采用实际的角色 ID - 例如,如果角色“a”的 ID 为 10,则 http://mysite .com/10 也会返回相同的结果。
如果您只想查找角色名,则可以修改挂钩,使其在找不到角色时失败(只需使 $rid = 0 并且您不应该得到任何结果)。
I think you mean you want to use an Argument, rather than the query string. In any case, I don't think Views can handle rolenames by default (it can handle role IDs just fine), so you'll have to modify your view query in order to achieve what you want.
First, add User: Roles as an argument in your View. Then, in a custom module, implement hook_views_query_alter() and modify the query by replacing the rolename with its role ID.
So, for example, if your url is http://mysite.com/a, then it will look up the ID of role 'a', then find all nodes by an author with that role. It will also take the actual role ID - for example, if the ID of role 'a' is 10, then http://mysite.com/10 will also return the same result.
If you want it only to look up rolenames, you can modify the hook to fail when it doesn't find the role (just make $rid = 0 and you shouldn't get any results).