Problem/Motivation

0. Check contextual links work on the front page.
1. Enable content translation module. (Don't even need to configure anything for translation)
2. Go back to front page. See all contextual links killed.

Look at network debugger, the contextual links route returned with: 500 error "A fatal error occurred: Contextual link plugin (content_translation.contextual_links:menu_link) definition must include "route_name".".

Proposed resolution

Not all contextual links have a route to back them up, since the translation tab only shows if the entity bundle is translatable. The contextual link should not be kept then either.

Remaining tasks

Review.

User interface changes

Contextual links work even with content translation enabled.

API changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Gábor Hojtsy’s picture

Priority: Normal » Major

Probably major enough.

swentel’s picture

Status: Active » Needs review
FileSize
1.27 KB

The route exist, but afaics, the check in getDerivativeDefinitions() in ContentTranslationContextualLinks.php should be harder.

Looking at content_translation_entity_info_alter(), the 'translation' is added always, but the 'drupal:content-translation-overview' only gets added when there's a canonical URL. However, we only do an isset() on the translation key and that always will be true.

Now, I'm not even sure if this is safe enough as it's entirely possible someone else could alter into the content_translation array and adds more stuff. So maybe an !empty($entity_info['translation']['links']['drupal:content-translation-overview']) ?

Gábor Hojtsy’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

@swentel: yay, good find! I think we should specifically check for the route $entity_info['translation']['links']['drupal:content-translation-overview']. This also makes sure if this changes later on, that it will be fixed again. Also config translation has tests for contextual links, so we should do that here too to ensure this does not break again.

This may be the reason also for #2154709: "No translatable fields" link points to misleading place. (translation tabs show even if an entity type is not translatable :D). Maybe we need to move that part here and fix it here, since it would be the same fix but on the tab plugins like on the contextual links :)

swentel’s picture

Ah, right, the fact that I saw that tab was indeed confusing me after just enabling the module :)
I'll check both, either this evening, or over the weekend.

Gábor Hojtsy’s picture

Title: Enabling content translation kills contextual links » Contextual links broken, tabs erroneously added after enabling content translation module

Ok rescoped for those two then. Descoping the other issue.

Gábor Hojtsy’s picture

Title: Contextual links broken, tabs erroneously added after enabling content translation module » Regression: Contextual links broken, tabs erroneously added after enabling content translation module
Issue tags: +Regression
Gábor Hojtsy’s picture

@swentel: are you still on this? :)

swentel’s picture

@gabor extremely limited in time in december - as early as mid january actually ...

Gábor Hojtsy’s picture

Status: Needs work » Needs review
FileSize
3.39 KB

All right, here is an alternate patch. I realized the logic we would have introduced is equal to the logic in ContentTranslationManager::isSupported() which is indirectly used in ContentTranslationLocalTasks to put on the translation tabs. (It checks for translatability and the existence of the route). So we can inject the ContentTranslationManager instead of the entity manager and do very similar to the local task implementation basically. This should expose the same bugs at the two places (if any :D).

No additional tests yet.

YesCT’s picture

FileSize
478.43 KB

@pwolanin found also

Uncaught PHP Exception Drupal\Component\Plugin\Exception\PluginException: "Contextual link plugin (content_translation.contextual_links:menu_link) definition must include "route_name"." at /Users/Shared/www/drupal-8/core/lib/Drupal/Core/Menu/ContextualLinkManager.php line 115

I can find the same with "tail /Applications/MAMP/logs/php_error.log" (found the error log location by checking phpinfo.php

in firebug:

watchdog entry:

Notice: Undefined index: drupal:content-translation-overview in Drupal\content_translation\Plugin\Derivative\ContentTranslationContextualLinks->getDerivativeDefinitions() (line 57 of /Users/ctheys/foo/drupal2/core/modules/content_translation/lib/Drupal/content_translation/Plugin/Derivative/ContentTranslationContextualLinks.php).

webchick’s picture

I got that yesterday, but a fresh reinstall solved it.

YesCT’s picture

+++ b/core/modules/content_translation/lib/Drupal/content_translation/Plugin/Derivative/ContentTranslationContextualLinks.php
@@ -50,13 +50,11 @@ public static function create(ContainerInterface $container, $base_plugin_id) {
-      if ($entity_info['translatable'] && isset($entity_info['translation'])) {

huh, there are special content translation contextual links.

so.. this takes out the if?

pfrenssen’s picture

FileSize
3.41 KB

Status: Needs review » Needs work

The last submitted patch, 13: 2154701-13.patch, failed testing.

pfrenssen’s picture

Status: Needs work » Needs review
FileSize
8.33 KB
6.14 KB

Fixed the test failure and started working on a test. For some reason the contextual link is not yet showing up in the test, I am still missing something.

The last submitted patch, 15: 2154701-15.patch, failed testing.

pfrenssen’s picture

Assigned: Unassigned » pfrenssen

Going to work on this.

pfrenssen’s picture

FileSize
8.39 KB
1.37 KB

Was missing the "translate any entity" permission in the test. This one should be green.

The test is not very optimal, I was lazy and extended ContentTranslationTestBase which does a lot of unrelated stuff which makes this test rather slow. I will make a leaner version of the test.

pfrenssen’s picture

Assigned: pfrenssen » Unassigned
FileSize
8.03 KB
4.61 KB
4.65 KB

Rewrote the test.

Before:

$ time sudo -u http php run-tests.sh --url http://drupal.local/ --class "\Drupal\content_translation\Tests\ContentTranslationContextualLinksTest"

Drupal test run
---------------

Tests to be run:
 - Content translation contextual links (\Drupal\content_translation\Tests\ContentTranslationContextualLinksTest)

Test run started:
 Friday, January 10, 2014 - 14:49

Test summary
------------

Content translation contextual links 67 passes, 0 fails, and 0 exceptions

Test run duration: 1 min 19 sec


real	1m20.141s
user	0m43.560s
sys	0m0.677s

After:

$ time sudo -u http php run-tests.sh --url http://drupal.local/ --class "\Drupal\content_translation\Tests\ContentTranslationContextualLinksTest"

Drupal test run
---------------

Tests to be run:
 - Content translation contextual links (\Drupal\content_translation\Tests\ContentTranslationContextualLinksTest)

Test run started:
 Friday, January 10, 2014 - 15:37

Test summary
------------

Content translation contextual links 17 passes, 0 fails, and 0 exceptions

Test run duration: 20 sec


real	0m20.457s
user	0m10.437s
sys	0m0.320s

From 1m20s to 20s, nice improvement :)

Unassigning myself, work here is complete. Reviews welcome!

The last submitted patch, 18: 2154701-18.patch, failed testing.

Gábor Hojtsy’s picture

Issue summary: View changes

Looks great, thanks for optimising the tests as well. Updated the issue summary as well. Can we make the test a bit more robust though? Ie. enable translatability in the test method itself so we can check first that the translate tab & contextual link is not yet there and then check that it works afterwards (as is now). That would be a more complete approach. Now this only checks the translate tab and contextual links after the setup.

pfrenssen’s picture

Assigned: Unassigned » pfrenssen
Status: Needs review » Needs work

Certainly. I still have half an hour before our glorious New Year Winter Barbeque™, hopefully will be able to make some progress in that time.

pfrenssen’s picture

Ok so there is something interesting going on here. Apparently $entity_info->isTranslatable() is always TRUE, even if translations have been disabled in the interface. At least for nodes this is the case.

I have no time left to work on this today unfortunately.

pfrenssen’s picture

Gábor Hojtsy’s picture

Status: Needs work » Reviewed & tested by the community

That sounds like it would be out of scope here. The patch fixes the problem in scope and we need another issue for node bundles always being translatable. :D I think this fix is good to go as-is then. It would be good to cover the pre-translation enablement in that other issue.

The last submitted patch, 19: 2154701-19-test_only.patch, failed testing.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Great work!

Committed and pushed to 8.x. Thanks!

Gábor Hojtsy’s picture

Yay, thanks @pfrenssen for looking at this!

Can you open an issue about the translation flag being always on for node types? Is that true for other entities? Hopefully not :)

Gábor Hojtsy’s picture

Issue tags: -sprint

Status: Fixed » Closed (fixed)

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

pfrenssen’s picture

@Gabor, regarding your question in #28. I have tested this in the latest 8.x and it occurs for all entities. I have opened an issue about it: #2188675: "Translate" local task always visible, leads to WSOD.