Unverified Commit 547bcff6 authored by alexpott's avatar alexpott

Issue #2986898 by kswamy, seanB, anmolgoyal74, tstoeckler: Can't delete the translation of a media

(cherry picked from commit 4cafe992)
parent 140b01f0
......@@ -60,6 +60,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
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 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state->setRedirectUrl($this->getRedirectUrl());
}
$this->messenger()->addStatus($this->getDeletionMessage());
$this->messenger()->addStatus($message);
$this->logDeletionMessage();
}
......
......@@ -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;
}
/**
......
<?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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment