Problem/Motivation

404 and 403 pages are broken. They return Invalid content type requested.

Steps to reproduce

1. Configure custom 404 and 403 pages on admin/config/system/site-information.
2. Visit a non-existent path.

Proposed resolution

The issue lies in handleClientErrorResponses method of CustomElementsViewSubscriber class. Condition to get route name doesn't match `system.4*` because request is forwarded to the node that is a custom error page. Another way to check whether we were redirected to 40x page is by checking the status code query parameter that is added in makeSubrequest method. We also have to change the way custom element slot is set, because $result is render array and doesn't yet have #markup attribute.

I'm not sure that first if condition is still necessary, but I left it in for backwards compatibility.

  if (!$result instanceof CustomElement) {
      $status_code = $event->getRequest()->get('_exception_statuscode');
      if (strpos($this->getCurrentRouteMatch()->getRouteName(), 'system.4') === 0) {
        $event->setControllerResult(CustomElement::create('drupal-markup')
          ->setSlot('default', $result['#markup'])
        );
      }
      elseif (isset($status_code) && in_array($status_code, [401, 403, 404])) {
        $event->setControllerResult(CustomElement::create('drupal-markup')
          ->setSlotFromRenderArray('default', $result)
        );
      }
    }
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

useernamee created an issue. See original summary.

useernamee’s picture

Here is a patch.

fago’s picture

Status: Active » Reviewed & tested by the community

The patch looks good and works exactly as it should. Ready to go.

mostepaniukvm made their first commit to this issue’s fork.

mostepaniukvm’s picture

Status: Reviewed & tested by the community » Fixed
mostepaniukvm’s picture

Status: Fixed » Closed (fixed)