summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2018-09-19 08:56:47 (GMT)
committerAlex Pott2018-09-19 08:56:54 (GMT)
commit547bcff64860580fc4bd502be3175822065511ef (patch)
treedf3526f8d5cb4ad26ce873b9222faac3b90a4ba5
parent140b01f0e9bb29c83958bbb04f9515be9254e7ea (diff)
Issue #2986898 by kswamy, seanB, anmolgoyal74, tstoeckler: Can't delete the translation of a media
(cherry picked from commit 4cafe992ace3a85114bff18c2e254e37b9a69699)
-rw-r--r--core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php3
-rw-r--r--core/modules/media/src/Entity/Media.php9
-rw-r--r--core/modules/media/tests/src/Functional/MediaTranslationUITest.php96
3 files changed, 102 insertions, 6 deletions
diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php b/core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php
index 94af017..27dd2b7 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php
@@ -60,6 +60,7 @@ class ContentEntityDeleteForm extends ContentEntityConfirmFormBase {
public function submitForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $this->getEntity();
+ $message = $this->getDeletionMessage();
// Make sure that deleting a translation does not delete the whole entity.
if (!$entity->isDefaultTranslation()) {
@@ -73,7 +74,7 @@ class ContentEntityDeleteForm extends ContentEntityConfirmFormBase {
$form_state->setRedirectUrl($this->getRedirectUrl());
}
- $this->messenger()->addStatus($this->getDeletionMessage());
+ $this->messenger()->addStatus($message);
$this->logDeletionMessage();
}
diff --git a/core/modules/media/src/Entity/Media.php b/core/modules/media/src/Entity/Media.php
index 1bbaf08..c218210 100644
--- a/core/modules/media/src/Entity/Media.php
+++ b/core/modules/media/src/Entity/Media.php
@@ -91,15 +91,14 @@ class Media extends EditorialContentEntityBase implements MediaInterface {
* {@inheritdoc}
*/
public function getName() {
- $name = $this->get('name');
+ $name = $this->getEntityKey('label');
- if ($name->isEmpty()) {
+ if (empty($name)) {
$media_source = $this->getSource();
return $media_source->getMetadata($this, $media_source->getPluginDefinition()['default_name_metadata_attribute']);
}
- else {
- return $name->value;
- }
+
+ return $name;
}
/**
diff --git a/core/modules/media/tests/src/Functional/MediaTranslationUITest.php b/core/modules/media/tests/src/Functional/MediaTranslationUITest.php
new file mode 100644
index 0000000..78a4e17
--- /dev/null
+++ b/core/modules/media/tests/src/Functional/MediaTranslationUITest.php
@@ -0,0 +1,96 @@
+<?php
+
+namespace Drupal\Tests\media\Functional;
+
+use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
+use Drupal\Tests\media\Traits\MediaTypeCreationTrait;
+
+/**
+ * Tests the Media Translation UI.
+ *
+ * @group media
+ */
+class MediaTranslationUITest extends ContentTranslationUITestBase {
+
+ use MediaTypeCreationTrait;
+
+ /**
+ * {inheritdoc}
+ */
+ protected $defaultCacheContexts = [
+ 'languages:language_interface',
+ 'theme',
+ 'timezone',
+ 'url.query_args:_wrapper_format',
+ 'user.permissions',
+ ];
+
+ /**
+ * {inheritdoc}
+ */
+ public static $modules = [
+ 'language',
+ 'content_translation',
+ 'media',
+ 'media_test_source',
+ ];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ $this->entityTypeId = 'media';
+ $this->bundle = 'test';
+ parent::setUp();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setupBundle() {
+ $this->createMediaType('test', [
+ 'id' => $this->bundle,
+ 'queue_thumbnail_downloads' => FALSE,
+ ]);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getTranslatorPermissions() {
+ return array_merge(parent::getTranslatorPermissions(), [
+ 'administer media',
+ 'edit any test media',
+ ]);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getEditorPermissions() {
+ return ['administer media', 'create test media'];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getAdministratorPermissions() {
+ return array_merge(parent::getAdministratorPermissions(), [
+ 'access administration pages',
+ 'administer media types',
+ 'access media overview',
+ 'administer languages',
+ ]);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getNewEntityValues($langcode) {
+ return [
+ 'name' => [['value' => $this->randomMachineName()]],
+ 'field_media_test' => [['value' => $this->randomMachineName()]],
+ ] + parent::getNewEntityValues($langcode);
+ }
+
+}