Problem/Motivation

Simply installing Content Translation on a site with rest resources breaks those resources. This is because Content Translation adds drupal:content-translation-overview links (and others) to entities, but it does not declare those relation types. Rest resource URLs throw an unhandled exception due to this.

Note that this was found (somewhat by accident) in #3367475: [meta] Improve support for entity types without a canonical link but also has come up in #2135829: EntityResource: translations support.

See also #3088282: Missing Views link relationships when Views UI installed for a similar issue where Views UI did not provide link relation types for links it was using.

Steps to reproduce

  1. Install Rest and Node and visit the shipped node resource for a given node.
  2. Install Content Translation.
  3. Reload the resource.

Proposed resolution

Provide the respective link relation types.

Remaining tasks

Subsystem maintainer review

User interface changes

-

API changes

-

Data model changes

Content Translation now provides the following link relation types:

  • drupal:content-translation-overview
  • drupal:content-translation-add
  • drupal:content-translation-edit
  • drupal:content-translation-delete

Release notes snippet

CommentFileSizeAuthor
#3 3368071-3.patch5.39 KBtstoeckler
#2 3368071-2.patch4.25 KBtstoeckler

Issue fork drupal-3368071

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

tstoeckler created an issue. See original summary.

tstoeckler’s picture

Issue summary: View changes
Status: Active » Needs review
Related issues: +#3088282: Missing Views link relationships when Views UI installed
StatusFileSize
new4.25 KB

Here's a test only patch to prove the bug. I opted to simply installing Content Translation in the respective rest resource base classes instead of adding dedicated tests as there really is no translation-related functionality that we are testing here. It's simply about the fact that the resources work as before even with Content Translation enabled. But I guess this is arguable and could be changed, as well.

Didn't check why the language cache context is bubbled in the resources, but it doesn't seem problematic to me.

tstoeckler’s picture

StatusFileSize
new5.39 KB

And here's the fix. Stole the comment in the YAML file from the Views UI implementation in case anyone is wondering.

The last submitted patch, 2: 3368071-2.patch, failed testing. View results

senthilmohith’s picture

Assigned: Unassigned » senthilmohith
smustgrave’s picture

Version: 9.5.x-dev » 11.x-dev
Assigned: senthilmohith » Unassigned

@SenthilMohith thank you for the interest but shouldn't assign tickets to yourself unless a maintainer per https://www.drupal.org/docs/develop/issues/issue-procedures-and-etiquett...

queuing for 11.x tests.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Tests all green.

Also ran a test locally without the fix file and the testGet() failed with

Drupal\Component\Plugin\Exception\PluginNotFoundException : The "drupal:content-translation-overview" plugin does not exist. Valid plugin IDs for Drupal\Core\Http\LinkRelationTypeManager are: add-form, add-page, delete-form, delete-multiple-form, revision, revision-revert-form, revision-delete-form, create, enable, disable, edit-permissions-form, overview-form, reset-form, cancel-form, flush-form, duplicate-form, about, alternate, appendix, archives, author, blocked-by, bookmark, canonical, chapter, collection, contents, copyright, create-form, current, customize-form, derivedfrom, describedby, describes, disclosure, dns-prefetch, duplicate, edit, edit-form, edit-media, enclosure, first, glossary, help, hosts, hub, icon, index, item, last, latest-version, license, lrdd, memento, monitor, monitor-group, next, next-archive, nofollow, noreferrer, original, payment, pingback, preconnect, predecessor-version, prefetch, preload, prerender, prev, preview, previous, prev-archive, privacy-policy, profile, related, replies, search, section, self, set-default, service, start, stylesheet, subsection, successor-version, tag, terms-of-service, timegate, timemap, type, up, version-history, via, webmention, working-copy, working-copy-of, entity-permissions-form

Think this is good.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 3: 3368071-3.patch, failed testing. View results

tstoeckler’s picture

Status: Needs work » Reviewed & tested by the community

Random failure, back to RTBC

longwave’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/content_translation/content_translation.link_relation_types.yml
@@ -0,0 +1,14 @@
+drupal:content-translation-overview:
...
+drupal:content-translation-add:
...
+drupal:content-translation-edit:
...
+drupal:content-translation-delete:

Why are these prefixed with drupal:? No other Drupal-specific link relations have this prefix.

smustgrave’s picture

Status: Needs review » Needs work

True. Moving to NW to update links.

tstoeckler’s picture

Status: Needs work » Needs review

First of all, not sure that's true. canonical, edit-form, etc. are all standard IANA link relation types. The idea was to use the drupal: prefix for all custom ones. We may not have followed through on that correctly, not sure off the top of my head.

But regardless, this is not establishing the content translation link relation types, they already exist and are being used. They are just missing their declaration. And Rest module happens to ve particularly strict about that.

So moving back to needs review as I'm not sure what else could be done here.

tstoeckler’s picture

Issue summary: View changes

Any response @longwave or @smustgrave? Per the above I don't think the criticism of the patch was warranted. I also took another look at the issue summary and I think the situation is explained sufficiently there, as well. Not going to re-RTBC myself because people are very sensitive with that, but maybe either of you can confirm and do so? Would be much appreciated.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Going to put in committer bucket to get more eyes on it.

Not sure I could make the call.

tstoeckler’s picture

Great, thanks!

quietone’s picture

Issue summary: View changes
Issue tags: +Needs subsystem maintainer review

I'm triaging RTBC issues. I read the IS and the comments.

Thanks for answering longwave's query. Due to the adding of the prefix, this should have subsystem maintainer review first (I checked with xjm)

longwave’s picture

Oh I see:

        if (!$entity_type->hasLinkTemplate('drupal:content-translation-overview')) {
          $translations_path = $entity_type->getLinkTemplate('canonical') . '/translations';
          $entity_type->setLinkTemplate('drupal:content-translation-overview', $translations_path);
          $entity_type->setLinkTemplate('drupal:content-translation-add', $translations_path . '/add/{source}/{target}');
          $entity_type->setLinkTemplate('drupal:content-translation-edit', $translations_path . '/edit/{language}');
          $entity_type->setLinkTemplate('drupal:content-translation-delete', $translations_path . '/delete/{language}');
        }

So we already declare these link templates - this code has existed since 8.0. But we didn't define the metadata for them, which REST module requires. Changing these now would break backward compatibility with code that already uses them, which is out of scope of this issue.

tstoeckler’s picture

Re #16: Again, this is not adding a prefix. It's just formally declaring, i.e. in a sense documenting, something that is already used. Subsystem maintainer review never hurts, so I have no issue with adding that tag, but wanted to point that out.

Re #17: Exactly. I tried to explain this in the issue summary, but maybe I didn't do a super good job. But that is exactly the point.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 3: 3368071-3.patch, failed testing. View results

tstoeckler’s picture

Status: Needs work » Reviewed & tested by the community
needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work

The Needs Review Queue Bot tested this issue.

While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

tstoeckler’s picture

Status: Needs work » Reviewed & tested by the community

Yup, back to RTBC then. Just pushed the patch to an MR, so the RTBC from #14 still applies.

  • catch committed 8451a498 on 10.3.x
    Issue #3368071 by tstoeckler, longwave: Installing Content Translation...

  • catch committed 33d2e033 on 10.4.x
    Issue #3368071 by tstoeckler, longwave: Installing Content Translation...

  • catch committed ac56748d on 11.0.x
    Issue #3368071 by tstoeckler, longwave: Installing Content Translation...

  • catch committed 45bcde63 on 11.x
    Issue #3368071 by tstoeckler, longwave: Installing Content Translation...
catch’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs subsystem maintainer review

OK @tstoeckler's explanation means we don't need subsystem maintainer review, just a misunderstanding about the links already existing (which I also would have done probably).

Committed/pushed to 11.x and cherry-picked back through to 10.3.x, thanks!

Status: Fixed » Closed (fixed)

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

xjm’s picture

Belatedly crediting myself for release management review, and @quietone for asking the question.