Problem/Motivation

When there is no canonical link template, an exception is thrown.

Proposed resolution

Add a check for the template in path_entity_translation_delete.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sasanikolic’s picture

Status: Active » Needs review
Issue tags: +Needs tests
FileSize
907 bytes

Added the check.

miro_dietiker’s picture

Status: Needs review » Needs work

Back to work for the missing tests.

sasanikolic’s picture

Added the test to check the removal of canonical link templates.

Berdir’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests
  1. +++ b/core/modules/path/src/Tests/PathNoCanonicalLinkTest.php
    @@ -0,0 +1,74 @@
    +
    +namespace Drupal\path\Tests;
    +use Drupal\content_translation_test\Entity\EntityTestTranslatableUISkip;
    +use Drupal\language\Entity\ConfigurableLanguage;
    

    missing empty line between namespace and use.

  2. +++ b/core/modules/path/src/Tests/PathNoCanonicalLinkTest.php
    @@ -0,0 +1,74 @@
    +    // Create test user and login.
    +    $admin_user = $this->drupalCreateUser(array(
    +      'translate any entity',
    +      'administer content translation',
    +      'administer languages',
    +      'administer content types',
    +    ));
    +    $this->drupalLogin($admin_user);
    ...
    +    // Visit the content translation.
    +    $this->drupalGet('admin/config/regional/content-language');
    +
    +    $this->assertText('Test entity - Translatable skip UI check');
    +    $this->assertText('Test entity - Translatable check UI (Translation is not supported)');
    +
    +    $edit = array(
    +      'entity_types[entity_test_translatable_UI_skip]' => 'entity_test_translatable_UI_skip',
    +      'settings[entity_test_translatable_UI_skip][entity_test_translatable_UI_skip][translatable]' => TRUE,
    +      'settings[entity_test_translatable_UI_skip][entity_test_translatable_UI_skip][settings][language][language_alterable]' => TRUE,
    +    );
    +    $this->drupalPostForm(NULL, $edit, t('Save configuration'));
    +    $this->drupalGet('admin/config/regional/content-language');
    

    I don't think we need any of this, this all doesn't matter for an API test.

    We should even be able to make this a fast kernel test.

Also, please provide a failing test-only patch.

sasanikolic’s picture

Removed the extra code and adding the test only patch (which is supposed to fail).

Status: Needs review » Needs work

The last submitted patch, 5: exception_when_deleting-2539222-5-test-only.patch, failed testing.

LKS90’s picture

Status: Needs work » Reviewed & tested by the community

Looks good! Tried switching to a Kernel test, but that doesn't seem so easy (added the language module, added the user module, now it complains about a missing table [entity_test_mul, I also tried added entity_test to the list of modules and installing the schema for it in the setUp, nothing worked]).

Berdir’s picture

Status: Reviewed & tested by the community » Needs work
Related issues: +#2539634: PathItem::delete() never runs because the path field type is a computed field in disguise

Looks good, but the test shouldn't be named KernelTest if it isn't one ;)

Also, I've recently found: #2539634: PathItem::delete() never runs because the path field type is a computed field in disguise

If I'm not mistaken then we can implement that issue in a way that will fix the problem here, you might want to consider working on that so we know if we can really replace that hook completely.

sasanikolic’s picture

Renamed the test.

LKS90’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to go.

miro_dietiker’s picture

Status: Reviewed & tested by the community » Postponed

Mind the Berdir statement at #8 and check #2539634: PathItem::delete() never runs because the path field type is a computed field in disguise

I'm postponing this for the other... Please explain the resulting situation if you need to reopen it, or close it as a duplicate if it solves the problem.

Berdir’s picture

Status: Postponed » Reviewed & tested by the community

Yes, but turns out that what I proposed in that other issue isn't actually how it works for field items at the moment, they are *not* called when a translation is removed. Which very likely is a bug but possibly not easy to fix.

So, let's get this in and then we have the test coverage to make sure this works, even if we end up removing that hook.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 9: exception_when_deleting-2539222-9.patch, failed testing.

olli’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/path/src/Tests/PathNoCanonicalLinkTest.php
    @@ -0,0 +1,52 @@
    +class PathNoCanonicalLinkTest extends PathTestBase {
    

    There is no need for this to be a WebTestBase test. It could be KernelTestBase afaics.

  2. +++ b/core/modules/path/src/Tests/PathNoCanonicalLinkTest.php
    @@ -0,0 +1,52 @@
    +    $entity_type->addTranslation('de', ['name' => 'name italian']);
    

    name italian for a de language? A bit confusing.

sasanikolic’s picture

Converted to a kernel test and changed the translation name.

juanse254’s picture

Status: Needs review » Reviewed & tested by the community

Passing tests, tested manually and works. Code seems fine as well setting to RTBC.

Berdir’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/path/src/Tests/PathNoCanonicalLinkTest.php
@@ -15,19 +16,37 @@
+    // In order to reflect the changes for a multilingual site in the container
+    // we have to rebuild it.
+    ConfigurableLanguage::create(['id' => 'de'])->save();

That comment doesn't make sense to me, what are we rebuilding? We just add a language.

Also, the negotation stuff below very likely isn't needed here.

sasanikolic’s picture

Rebased, fixed the comment and removed the "noegotation stuff" below.

dawehner’s picture

+++ b/core/modules/path/src/Tests/PathNoCanonicalLinkTest.php
@@ -0,0 +1,64 @@
+ */
+class PathNoCanonicalLinkTest extends KernelTestBase {
+

Note: You could also write a phpunit based kerneltestbase, actually everything should work the same

sasanikolic’s picture

Changed the path for KernelTestBase and moved the test into \Drupal\path\tests\Kernel.

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Ok, looks good to me now.

catch’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/path/tests/src/Kernel/PathNoCanonicalLinkTest.php
@@ -0,0 +1,64 @@
+ * Tests the Path when no canonical link template.

'when there is no'?

catch’s picture

Priority: Normal » Major

Apart from that nitpick looks good.

Also bumping to major.

sasanikolic’s picture

The last submitted patch, 21: exception_when_deleting-2539222-21.patch, failed testing.

miro_dietiker’s picture

Status: Needs review » Reviewed & tested by the community

Setting to RTBC since the fix cleanly implements what catch asked.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.1.x and cherry-picked to 8.0.x. Thanks!

  • catch committed c0b80f1 on 8.1.x
    Issue #2539222 by sasanikolic: Exception when deleting a translation...

  • catch committed 252733b on 8.0.x
    Issue #2539222 by sasanikolic: Exception when deleting a translation...

Status: Fixed » Closed (fixed)

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