2017-12-19 6 views
0

나는이 질문을하는 방법조차 모른다. 위의 코드에서 (위의 예제에서 찾았습니다.) 기본 조작자와 함께 다른 조작자를 추가하여 형제 외의 모든 링크를 제거하려고합니다.Drupal 8 - 조작자를 추가하는 방법

$manipulators = array(
    array('callable' => 'menu.default_tree_manipulators:checkAccess'), 
    array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'), 
    // This is what i want to do. Remove all links outside of siblings and active trail 
    array('callable' => 'mytheme.menu_transformers:removeInactiveTrail'), 
); 

클래스의 'removeInactiveTrail'메소드를 배치 할 위치는 어디입니까?

드루팔 (Drupal)에 익숙하지 않습니다. 질문이 너무 애처로운 경우 미안 해요.

답변

1

Drupal 초보자는 올바른 질문을하는 것이 항상 어렵습니다. 그러나 당신이 그 일을 수행하고 자신의 임무를 수행하는 스 니펫을 발견했다면, 핵심 모듈과 contrib 모듈을 연구하여 다른 사람들이 이러한 기능과 방법을 사용하는 방법을 찾는 것이 낫습니다.

구현이 확실하지 않은 경우 달성하고자하는 것에 대한 세부 정보를 추가하십시오.

다음은 사용자 정의 모듈에서 사용할 수있는 예제 :

function mymodule_render_menu($menu_name) { 
    $menu_tree = \Drupal::menuTree(); 
    // Build the typical default set of menu tree parameters. 
    $parameters = $menu_tree->getCurrentRouteMenuTreeParameters($menu_name); 
    // Load the tree based on this set of parameters. 
    $tree = $menu_tree->load($menu_name, $parameters); 

    // Transform the tree using the manipulators you want. 
    $manipulators = [ 
    // Add your manipulators here 
    ]; 

    $tree = $menu_tree->transform($tree, $manipulators); 
    // Finally, build a renderable array from the transformed tree. 
    $menu = $menu_tree->build($tree); 

    return array('#markup' => render($menu)); 
} 

위의 기능은 렌더링 가능한 배열을 반환합니다. hook_preprocess_HOOK에서 호출하여 변수 배열에 추가하고 템플릿에 출력 할 수 있습니다.

다시 말해, 작업이 명확하지 않아서 질문을보다 구체적으로 수정하십시오.