Problem/Motivation

lupus_ce_renderer requires Metatag:

  • lupus_ce_renderer.info.yml lists metatag:metatag under dependencies.
  • composer.json requires "drupal/metatag": "^1.23 | ^2.0".

lupus_decoupled and its submodules require lupus_ce_renderer, so every Lupus Decoupled site has to install Metatag. That includes decoupled applications that are deliberately not indexed, such as authenticated tools and embedded calculators or widgets. They don't use page metatags at all, but still have to install and maintain Metatag.

Metatag is only used in one place at runtime:

  1. CustomElementsMetatagsGenerator::getMetatags() calls metatag_generate_entity_all_tags() on node routes without checking moduleExists('metatag'). On non-node routes it already returns an empty meta/link structure.
  2. lupus_ce_renderer.custom_elements_renderer injects @metatag.manager into CustomElementsRenderer::__construct(). The constructor assigns it to $this->metatagManager, but nothing else in the class reads it. The renderer gets its metatags from the lupus_ce_renderer.ce_metatags_generator service.

Steps to reproduce

  1. Install lupus_decoupled 1.x with lupus_ce_renderer 2.7.0.
  2. Try to uninstall Metatag with drush pm:uninstall metatag, or remove drupal/metatag from composer.json.
  3. Drupal refuses because lupus_ce_renderer requires Metatag, and Composer refuses because drupal/lupus_ce_renderer requires drupal/metatag.

Proposed resolution

  1. Guard the metatags generator. In CustomElementsMetatagsGenerator::getMetatags(), only call metatag_generate_entity_all_tags() when Metatag is enabled and the route has a node. Otherwise use an empty list, so the response keeps the same metatags: { meta: [], link: [] } shape. The content_translation alternate links are still added.
    $node = $route_match->getParameter('node');
    $metatags = ($node !== NULL && $this->moduleHandler->moduleExists('metatag'))
      ? metatag_generate_entity_all_tags($node)
      : [];
    
  2. Remove the unused service argument. Drop @metatag.manager from the lupus_ce_renderer.custom_elements_renderer service definition, and drop the MetatagManagerInterface constructor parameter and $metatagManager property from CustomElementsRenderer. If changing the constructor counts as an API break, keep the parameter as optional and deprecated (?MetatagManagerInterface $metatagManager = NULL) and inject @?metatag.manager.
  3. Relax the dependency declarations.
    • Remove metatag:metatag from lupus_ce_renderer.info.yml.
    • Move drupal/metatag from require to suggest in composer.json.
    • Keep Metatag available to the test suite, so the existing metatag tests still run.
  4. Document it. Note in the README that page metatags in the API response require Metatag to be enabled.

Backwards compatibility

  • Sites with Metatag enabled see no change: same service behaviour, same response keys and values.
  • Sites without Metatag get the same response shape, with empty meta and only the translation link entries. The API contract for decoupled consumers doesn't change.
  • Composer-managed sites that currently get drupal/metatag only through lupus_ce_renderer will need to require it themselves. The release notes should say so.

Tests

  • Keep the existing Kernel tests that enable metatag (LupusCeRendererKernelTestBase, LupusCeRendererRequestsTest).
  • Add a Kernel test that enables the renderer without metatag and checks that:
    • a node route renders
    • the response contains metatags with empty meta and link

Remaining tasks

  • Agree whether to remove the MetatagManagerInterface constructor parameter or deprecate it.
  • Merge request with the changes above.
  • Add the test for rendering without Metatag.
  • Add a release note about requiring drupal/metatag explicitly.

User interface changes

None.

API changes

  • CustomElementsRenderer::__construct() no longer requires MetatagManagerInterface. It is either removed or accepted as an optional, deprecated argument.
  • drupal/metatag moves from a required to a suggested Composer package.

Data model changes

None.

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

glynster created an issue. See original summary.

fago’s picture

yes, that it is a good suggestion. plan is sound, MR welcome!

fago’s picture

Status: Active » Needs review

I added an MR, please review!

Note: I used AI to help with that, reviewed successfully!

fago’s picture

  • fago committed e037db8e on 2.x
    feat: #3623188 Make Metatag an optional dependency
    
    By: glynster
    By:...
fago’s picture

Status: Needs review » Fixed

code is ok, works fine, also proven by test. Merged!

Thank you glynster for providing the issue and the implementation plan!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.