Problem/Motivation

Link property of metatags object is empty.

{
  "title": "[de] test translation wf",
  "messages": [],
  "breadcrumbs": [
    { ... }
  ],
  "metatags": {
    "meta": [],
    "link": []
  },

Proposed resolution

CustomElementsMetatagsGenerator should take care of some configuration entities as well.

Result should look sth like this:

{
  "title": "[de] test translation wf",
  "messages": [],
  "breadcrumbs": [
    { ... }
  ],
  "metatags": {
    "meta": [],
    "link": [
      {
        "rel": "alternate",
        "hreflang": "de",
        "href": "https://admin--example.ldp-project.localdev.space/de/form/test-translation-wf"
      },
      {
        "rel": "alternate",
        "hreflang": "en",
        "href": "https://admin--example.ldp-project.localdev.space/form/test-translation-wf"
      }
    ]
  },
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

I've lessened the condition for metatags links generation. Check PR.

I'm also adding a patch file.

useernamee’s picture

Status: Active » Needs review
useernamee’s picture

This solution works for me, but I've just figured it out that it only adds webform translations if content_translation module is installed which is not optimal. https://git.drupalcode.org/project/lupus_ce_renderer/-/merge_requests/33...

This condition might need some more consideration.

fago’s picture

Status: Needs review » Needs work

> if (array_diff(['hasLinkTemplate', 'getTranslationLanguages'], get_class_methods($entity)) &&

This should check for the dedicated interface we need. each method should be provided by a suiting more narrow interface, content-entity-interface is a collection of those. Let's checked for the specific ones with an OR statement so this is a) nicer and b) easier to follow

> This solution works for me, but I've just figured it out that it only adds webform translations if content_translation module is installed which is not optimal. https://git.drupalcode.org/project/lupus_ce_renderer/-/merge_requests/33...

This is not really nice, indeed, but I think good enough. In practice only people having that module installed will want to have these metatags, so let's just keep doing it that way.

useernamee’s picture

Alternatively we could use:

if (($entity instanceof ContentEntityInterface || $entity instanceof WebformInterface) &&
        $entity->hasLinkTemplate('canonical') &&
        // Only add alternate link if entity is translated.
        count($entity->getTranslationLanguages()) > 1) {

but I don't like this solution either. getTranslationLanguages is defined on WebformInterface and the problem with this is that it is too specific for my taste. It might cause issues if webform is not installed. What would be proper fix would be to open an issue on webform to implement some proper translation interface with needed method.

ContentEntityInterface (ultimately) inherits the method from web/core/lib/Drupal/Core/TypedData/TranslatableInterface.php but that is not the case for Config entities.

useernamee’s picture

Assigned: useernamee » fago
fago’s picture

Could we do something like

if (($entity instanceof ContentEntityInterface ||
(class_exists(WebformInterface) && $entity instanceof WebformInterface))

? so we keep the check clean on interfaces, but still do work fine if webform module is not there. It also better documents why we are doing this. (webform)

  • 6f0ef973 committed on 3410567-webforms-are-missing
    #3410567: Fix condition to genereate alternate links for webforms.
    
useernamee’s picture

Status: Needs work » Needs review

I've implemented the last comment.

useernamee’s picture

I've created the new patch.

  • useernamee committed edcdaaea on 2.x
    Issue #3410567 by useernamee, fago: Webforms are missing metatags...
useernamee’s picture

Status: Needs review » Fixed

merged

Status: Fixed » Closed (fixed)

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