Drupal中的嵌套关系
我有一个D7网站,用户可以在那里制作内容(显然…)。所以每个节点都有自己的作者。每个作者都是一个组织的成员。但他可以是不止一个组织的成员。到目前为止,事实并非如此 我想创建一个视图,其中内容根据作者进行过滤。非常简单,在“内容的作者”上设置视图的关系,并选择当前用户作为过滤器。Drupal中的嵌套关系,drupal,nested,Drupal,Nested,我有一个D7网站,用户可以在那里制作内容(显然…)。所以每个节点都有自己的作者。每个作者都是一个组织的成员。但他可以是不止一个组织的成员。到目前为止,事实并非如此 我想创建一个视图,其中内容根据作者进行过滤。非常简单,在“内容的作者”上设置视图的关系,并选择当前用户作为过滤器。 但我想对作者的组织进行过滤。所以实际上这是一个嵌套关系。过滤当前登录用户上的节点(这很简单),但如何过滤当前登录用户的组织?好的,面板不起作用,所以我编写了自己的钩子:-) 我想你可能需要使用面板,而不仅仅是这里的视图一
但我想对作者的组织进行过滤。所以实际上这是一个嵌套关系。过滤当前登录用户上的节点(这很简单),但如何过滤当前登录用户的组织?好的,面板不起作用,所以我编写了自己的钩子:-)
我想你可能需要使用面板,而不仅仅是这里的视图一个面板可以显示基于另一个面板的结果我不是100%确定,但我认为这就是你在这里看到的好,我来看看面板模块!谢谢
function mymodule_views_pre_view (&$view, &$display_id, &$args) {
// Only execute this script when the view 'fiches_my_thema' is called
if ('fiches_my_thema' == $view->name) {
// Get users thema
global $user;
$userRoles = $user->roles;
$user_themas = array();
// Filter roles so you end up with the "Thema's".
foreach ($userRoles as $key) {
if(strpos($key,'edacteur')) {
$key = str_replace('Redacteur - ','', $key);
$key = str_replace('Eindredacteur - ','', $key);
$user_themas[] = $key;
}
}
// Resolve tid
$terms = taxonomy_get_tree(5);
$allRoles = array();
$arguments = array();
// Assign the 'tid' to a variable
foreach ($terms as $key) {
$singleRoles = $key->name;
$allRoles[] = $singleRoles;
if(in_array($singleRoles, $user_themas)) {
$arguments[] = $key->tid;
}
}
// Only when the arguments are NOT empty, set the arguments
if(!empty($arguments)) {
$finalArguments = implode("+", $arguments);
$args[] = "$finalArguments";
$view->set_arguments($args);
}
}
}