Load default 403/404 meta tags when node is used for those pages

Created on 24 August 2017, almost 8 years ago
Updated 24 April 2023, about 2 years ago

Following on from #2903661: Don't output 403/404 page node's meta tags on 403/404 pages โ†’ .

When a node is configured to be used for the site's 403 or 404 error pages, the meta tags configured at admin/config/search/metatags for those system pages is not loaded.

๐Ÿ› Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States damienmckenna NH, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia kasli_harshit

    Tried to apply the patch 2904468-13.patch , getting this error :

    Checking patch src/MetatagManager.php...
    Hunk #2 succeeded at 495 (offset 2 lines).
    Checking patch tests/src/Functional/MetatagHelperTrait.php...
    error: while searching for:

    use Drupal\Component\Render\FormattableMarkup;
    use Drupal\Component\Utility\Html;
    use Drupal\taxonomy\Entity\Term;
    use Drupal\taxonomy\Entity\Vocabulary;
    use Drupal\user\Entity\User;

    error: patch failed: tests/src/Functional/MetatagHelperTrait.php:4
    error: tests/src/Functional/MetatagHelperTrait.php: patch does not apply

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States daniel_j

    Re-rolled the patch in #14 to apply cleanly to 1.x-dev

  • Status changed to Needs review almost 2 years ago
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update almost 2 years ago
    372 pass
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States daniel_j
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia kasli_harshit

    Applied the Patch (#18) metatag-2904468-load_default_404_tags-18.patch , working as expected now the metatag values are rendering from backend 404/403 metatag settings , rather than node which is specified in 404 and 403 page settings.
    Adding the screenshot for the same. We can move this to RTBC+1.

  • Status changed to RTBC almost 2 years ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States daniel_j
  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฒ๐Ÿ‡ฝMexico dalin ๐Ÿ‡จ๐Ÿ‡ฆ, ๐Ÿ‡ฒ๐Ÿ‡ฝ, ๐ŸŒ

    Setting to "Needs Work" because
    * the latest patch seems to have lost the tests from #7
    * the latest patch doesn't apply on the 1.x branch, but should probably just go on the 2.x branch anyway.

    Upping to "normal" because the module is not doing what it says that it's going to do.

  • Status changed to Needs review over 1 year ago
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    run-tests.sh fatal error
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States cbfannin

    Rerolled for v2 and includes original tests.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    run-tests.sh fatal error
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States cbfannin

    My apologies. I was misusing phpcs locally and didn't catch those coding standard errors. Take 2!

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia prashant.c Dharamshala

    Prashant.c โ†’ made their first commit to this issueโ€™s fork.

  • Merge request !96Code refactor and phpcs fixes โ†’ (Open) created by prashant.c
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    run-tests.sh fatal error
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia prashant.c Dharamshala

    Utilized the patch supplied in #24 ๐Ÿ› Load default 403/404 meta tags when node is used for those pages Needs work , generated an MR containing phpcs corrections, and performed a minor code refactor.

    Thanks!

  • ๐Ÿ‡ฒ๐Ÿ‡พMalaysia ckng

    Created patch file from MR 96.

  • ๐Ÿ‡ฒ๐Ÿ‡พMalaysia ckng

    Rebased the MR and rerolled the patch file.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany Anybody Porta Westfalica

    @ckng MR needs to target 2.1.x - can you change that? I don't have permission.

  • Status changed to Needs work 3 months ago
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany SerkanB

    Maybe I'm the only one with this issue/request... but don't we want to show the metatags for 403/404 on the paths themselves as well?

    Like when I have a node/123 configured as 404-page and gave it the alias "/404-not-found". With the newest patch I get the metatags for 404 when I visit a alias that doesn't exist, which triggers the exception and everything. But when I go to "/404-not-found" I still get the default node metatags.

    My case might be a bit special, as we're doing a (kind of) static pages export. And for that I need to have the metatags on /404-not-found as well, so that page is exported with those and I can set up nginx to serve that page on a 404.

    For now I'll just have a patch for me, but if you guys think that makes sense in general, I can update the MR of course.

    Here is what I added to the MetatagManager.php (for anyone ending here, just like I did)

    ...
          elseif ($exception instanceof NotFoundHttpException) {
            $metatags = $this->metatagDefaults->load('404');
          }
        }
    // below are the new cases.
        else {
          $current_path = $this->request->getPathInfo();
          $path_alias_manager = \Drupal::service('path_alias.manager');
          $system_path = $path_alias_manager->getPathByAlias($current_path);
    
          if ($this->pathMatcher->matchPath($system_path, $this->configFactory->get('system.site')->get('page.403'))) {
            $metatags = $this->metatagDefaults->load('403');
          }
          elseif ($this->pathMatcher->matchPath($system_path, $this->configFactory->get('system.site')->get('page.404'))) {
            $metatags = $this->metatagDefaults->load('404');
          }
        }
    
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany SerkanB

    Attaching the patch, which is based on the patch #29, in case anyone else is in the same position as I am right now.

    Why am I not just adding that into the MR? I'm not sure about the performance implications on sites that aren't exported.
    Resolving the alias to the system path and comparing that agains the configures 403/404 paths... on every request (apparently multiple times). Sounds like trouble, if the page is on a prod-server with lots of requests.

    So you non-export guys decide if you want that in the MR or not :D

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany SerkanB

    Just found out I have to get the current request using the requestStack... TOME does magicโ„ข with the requestStack, but since the MetatagManager was invoked before that magicโ„ข it has loaded the old "request" into $this->request...

    Yeah, this is getting more and more TOME-export-specific I guess. Can we have an event/hook in getSpecialMetatags() maybe? So other modules could also decide if it's a special request or not?

Production build 0.71.5 2024