Allow other modules to hook into <head>

Created on 13 February 2024, over 1 year ago

Problem/Motivation

Features like ✨ Provide option to include canonical URL links Fixed are solvable by other modules in the eco system. The challenge here is that Printable has used a custom html template stripping out all the capabilities that Drupal has of manipulating HEAD, JS, or CSS. I get it, this is by design because you don't want that stuff cluttering up the printer friendly version of content.

However, it also means that we have to reinvent the wheel, AND that no customizations can be implemented without being added directly to the template itself.

For SEO purposes, it's extremely important that we have the ability to add metatags, but for that module to work, we must have the ability to alter the head.

Proposed resolution

I propose we add the original values for preprocessing Drupal's HEAD back into the template so that a metatag impelemtation can be used via metatag_routes, hook_metatags_alter(), or some custom module that may come to handle printable's metatags explicitly.

At MVP if the above isn't achievable is canonical and/or robots metatags such as noindex.

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States generalredneck Texas, USA πŸ‡ΊπŸ‡Έ

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

Comments & Activities

  • Issue created by @generalredneck
  • πŸ‡¦πŸ‡ΊAustralia nigelcunningham Geelong

    I agree.

    I'm planning on implementing a plugin / event based way of altering the content. The link extractor is currently a prime target and modifications like this would fit in well to such a rework.

    Hopefully not far away, though I'm checking through the issue queue for other ideas before starting on this.

  • πŸ‡¦πŸ‡ͺUnited Arab Emirates ThirstySix

    We need to preprocess the head for the development environment, such as adding a noindex meta tag. Need a invoke hook to enable other modules to modify the PDF response.

    For Ex:

    /**
     * Implements hook_printable_pdf_response_alter().
     */
    function HOOK_printable_pdf_response_alter(\Symfony\Component\HttpFoundation\Response $response) {
      // Check if the response is a PDF file
      if ($response->headers->get('Content-Type'), 'application/pdf') {
        // Add noindex, nofollow meta tag for PDF responses
        $response->headers->set('X-Robots-Tag', 'noindex, nofollow');
      }
    }
Production build 0.71.5 2024