在Ajax

时间:2019-05-02 12:12:24

标签: ajax drupal drupal-8

我有一个产品网站,每个产品都有一个类别和子类别。每个类别和子类别都有一个专用页面。

我的产品概述是带有一些暴露过滤器(材料,颜色,类别,子类别)的视图。如果用户位于专用页面上,则ex:类别页面的暴露过滤器“类别”设置为当前节点ID,过滤器被隐藏(暴露=假)。

这适用于初始页面加载。 但是,如果我更改过滤器(更改ex的彩色过滤器),则会执行Ajax调用,并且过滤器类别将再次显示,并且不再选择当前节点ID。

 /*
     * If view is products and block_1
     */
    if($view->id() == 'products') {
        if($view->current_display == 'block_1'){
            //Get current node
            $current_node = \Drupal::routeMatch()->getParameter('node');

            //If current node is a category set the category filter and de-expose the filter
            if(!empty($current_node) AND $current_node->bundle()=="category"){
                $filters = $view->display_handler->getOption('filters');
                foreach ($filters as $key => &$filter){
                    if($key=="field_category_node_target_id"){
                        $filter["value"]=array($current_node->id());
                        $filter["exposed"]=false;
                    }
                    //Color and material should only be exposed on lower levels
                    if($key=="field_main_material_target_id"){
                        $filter["exposed"]=false;
                    }
                    if($key=="field_main_color_target_id"){
                        $filter["exposed"]=false;
                    }
                }
                $view->display_handler->overrideOption('filters', $filters);
            }
            //If current node is a subcategory set the subcategory filter and de-expose the filter
            if(!empty($current_node) AND $current_node->bundle()=="subcategory"){
                $filters = $view->display_handler->getOption('filters');
                foreach ($filters as $key => &$filter){
                    if($key=="field_category_node_target_id"){
                        $filter["exposed"]=false;
                    }
                    if($key=="field_subcategory_target_id"){
                        $filter["value"]=array($current_node->id());
                        $filter["exposed"]=false;
                    }
                }
                $view->display_handler->overrideOption('filters', $filters);
            }
        }
    }

我想让Ajax调用通过此钩子循环吗?

0 个答案:

没有答案