summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2016-09-05 11:18:24 (GMT)
committerNathaniel Catchpole2016-09-05 11:18:24 (GMT)
commitfb18e30d934aab134943eceb93dd39f5070de0e8 (patch)
tree553ae94471fbcb860ed85287957a6ce0115a65d2
parenta1b670fb9a92d2e2966edfb3366d4d0550201635 (diff)
Revert "Issue #2787187 by claudiu.cristea, grahl, azinck: Data loss: Deleting a translation of an entity deletes all file_usage entries for files referenced by the entity"
This reverts commit a1b670fb9a92d2e2966edfb3366d4d0550201635.
-rw-r--r--core/modules/file/src/Plugin/Field/FieldType/FileFieldItemList.php6
-rw-r--r--core/modules/file/tests/src/Kernel/UsageTest.php60
2 files changed, 2 insertions, 64 deletions
diff --git a/core/modules/file/src/Plugin/Field/FieldType/FileFieldItemList.php b/core/modules/file/src/Plugin/Field/FieldType/FileFieldItemList.php
index 20f4797..3d064af 100644
--- a/core/modules/file/src/Plugin/Field/FieldType/FileFieldItemList.php
+++ b/core/modules/file/src/Plugin/Field/FieldType/FileFieldItemList.php
@@ -81,11 +81,9 @@ class FileFieldItemList extends EntityReferenceFieldItemList {
parent::delete();
$entity = $this->getEntity();
- // If a translation is deleted only decrement the file usage by one. If the
- // default translation is deleted remove all file usages within this entity.
- $count = $entity->isDefaultTranslation() ? 0 : 1;
+ // Delete all file usages within this entity.
foreach ($this->referencedEntities() as $file) {
- \Drupal::service('file.usage')->delete($file, 'file', $entity->getEntityTypeId(), $entity->id(), $count);
+ \Drupal::service('file.usage')->delete($file, 'file', $entity->getEntityTypeId(), $entity->id(), 0);
}
}
diff --git a/core/modules/file/tests/src/Kernel/UsageTest.php b/core/modules/file/tests/src/Kernel/UsageTest.php
index 8e26015..fdf1231 100644
--- a/core/modules/file/tests/src/Kernel/UsageTest.php
+++ b/core/modules/file/tests/src/Kernel/UsageTest.php
@@ -2,13 +2,6 @@
namespace Drupal\Tests\file\Kernel;
-use Drupal\field\Entity\FieldConfig;
-use Drupal\field\Entity\FieldStorageConfig;
-use Drupal\language\Entity\ConfigurableLanguage;
-use Drupal\language\Entity\ContentLanguageSettings;
-use Drupal\node\Entity\Node;
-use Drupal\node\Entity\NodeType;
-
/**
* Tests file usage functions.
*
@@ -210,57 +203,4 @@ class UsageTest extends FileManagedUnitTestBase {
$this->assertTrue(file_exists($perm_new->getFileUri()), 'New permanent file was correctly ignored.');
}
- /**
- * Tests file usage with translated entities.
- */
- public function testFileUsageWithEntityTranslation() {
- /** @var \Drupal\file\FileUsage\FileUsageInterface $file_usage */
- $file_usage = $this->container->get('file.usage');
-
- $this->enableModules(['node', 'language']);
- $this->installEntitySchema('node');
- $this->installSchema('node', ['node_access']);
-
- // Activate English and Romanian languages.
- ConfigurableLanguage::create(['id' => 'en'])->save();
- ConfigurableLanguage::create(['id' => 'ro'])->save();
-
- NodeType::create(['type' => 'page'])->save();
- ContentLanguageSettings::loadByEntityTypeBundle('node', 'page')
- ->setLanguageAlterable(FALSE)
- ->setDefaultLangcode('en')
- ->save();
- // Create a file field attached to 'page' node-type.
- FieldStorageConfig::create([
- 'type' => 'file',
- 'entity_type' => 'node',
- 'field_name' => 'file',
- ])->save();
- FieldConfig::create([
- 'entity_type' => 'node',
- 'bundle' => 'page',
- 'field_name' => 'file',
- 'label' => 'File',
- ])->save();
-
- // Create a node, attach a file and add a Romanian translation.
- $node = Node::create(['type' => 'page', 'title' => 'Page']);
- $node
- ->set('file', $file = $this->createFile())
- ->addTranslation('ro', $node->getTranslation('en')->toArray())
- ->save();
-
- // Check that the file is used twice.
- $usage = $file_usage->listUsage($file);
- $this->assertEquals(2, $usage['file']['node'][$node->id()]);
-
- // Remove the Romanian translation.
- $node->removeTranslation('ro');
- $node->save();
-
- // Check that one usage has been removed and is used only once now.
- $usage = $file_usage->listUsage($file);
- $this->assertEquals(1, $usage['file']['node'][$node->id()]);
- }
-
}