首頁>Web>source

情况:

  • A View page displays all "items" that have a certain "code".

  • The code is passed via a contextual filter, e.g. /items/17 ,其中17是代碼。

  • 使用者可能会尝試通過键入密碼来猜測密碼,例如 /items/345

  • 当视圖為空時(即代碼是偽造的),將引發以下未找到的異常:

    function mymodule_views_pre_render(\Drupal\views\ViewExecutable $view) {
      if ($view->current_display == 'page_machine_name' && empty($view->result)) {
        throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
      }
    }
    
  • "视圖"頁面頂部顯示有一个選單作為一个塊。

  • 選單塊配置將塊限製為具有路徑 /items/*的頁面

問题:

该選單也会出現在404頁面上,因為该頁面保留了偽路徑 /items/345 .如何从404頁中排除選單塊?

註意:

  • I want to display the default 404 page rather than the view with a "not found" message as its body.
  • I don't want to display the view as a block instead of as a page unless it's the only way. I already know how to solve the problem if I have to do that.
  • If there were a way to say, "Include this block only on View pages" (like you can for content types), that would be ideal.
  • There are actually three blocks that need to be excluded from the 404 page; I mention only one to make it simpler. The other blocks are a text block and a banner block.
  • I see that a solution to this problem has been proposed for Drupal 9, but not available yet.
最新回復
  • 7月前
    1 #

    是的,该解決方案尚無法在核心中使用,請參阅https://www.drupal.org/node/2245767。

    但是您可以使用此contrib模組https://www.drupal.org/project/block_in_page_not_found並否定不在404頁上顯示该塊的條件:

  • drupal:如何在节點編輯表單中將描述添加到主體欄位摘要視窗小部件?
  • wordpress:需要帮助纠正正則表達式重定向代碼