Issue #3218103 by phenaproxima, rpayanm, joachim: media module creates fields with the field prefix hardcoded and ignores the configuration
parent
68ba1bbeb1
commit
c10a6abed9
|
@ -301,9 +301,14 @@ abstract class MediaSourceBase extends PluginBase implements MediaSourceInterfac
|
|||
* returned. Otherwise, a new, unused one is generated.
|
||||
*/
|
||||
protected function getSourceFieldName() {
|
||||
// If the Field UI module is installed, and has a specific prefix
|
||||
// configured, use that. Otherwise, just default to using 'field_' as
|
||||
// a prefix, which is the default that Field UI ships with.
|
||||
$prefix = $this->configFactory->get('field_ui.settings')
|
||||
->get('field_prefix') ?? 'field_';
|
||||
// Some media sources are using a deriver, so their plugin IDs may contain
|
||||
// a separator (usually ':') which is not allowed in field names.
|
||||
$base_id = 'field_media_' . str_replace(static::DERIVATIVE_SEPARATOR, '_', $this->getPluginId());
|
||||
$base_id = $prefix . 'media_' . str_replace(static::DERIVATIVE_SEPARATOR, '_', $this->getPluginId());
|
||||
$tries = 0;
|
||||
$storage = $this->entityTypeManager->getStorage('field_storage_config');
|
||||
|
||||
|
|
|
@ -15,6 +15,11 @@ use Drupal\media\Entity\MediaType;
|
|||
*/
|
||||
class MediaSourceTest extends MediaKernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['field_ui'];
|
||||
|
||||
/**
|
||||
* Tests that metadata is correctly mapped irrespective of how media is saved.
|
||||
*/
|
||||
|
@ -506,6 +511,24 @@ class MediaSourceTest extends MediaKernelTestBase {
|
|||
$this->assertTrue($field->isRequired(), 'Field is not required.');
|
||||
$this->assertEquals('Test source with constraints', $field->label(), 'Incorrect label is used.');
|
||||
$this->assertSame('test_constraints_type', $field->getTargetBundle(), 'Field is not targeting correct bundle.');
|
||||
|
||||
// Test that new source fields respect the configured field prefix, no
|
||||
// prefix at all if that's what's configured.
|
||||
$this->installConfig('field_ui');
|
||||
$this->config('field_ui.settings')
|
||||
->set('field_prefix', 'prefix_')
|
||||
->save();
|
||||
$type = MediaType::create([
|
||||
'id' => $this->randomMachineName(),
|
||||
'label' => $this->randomString(),
|
||||
'source' => 'test',
|
||||
]);
|
||||
$this->assertSame('prefix_media_test', $type->getSource()->createSourceField($type)->getName());
|
||||
|
||||
$this->config('field_ui.settings')
|
||||
->set('field_prefix', '')
|
||||
->save();
|
||||
$this->assertSame('media_test', $type->getSource()->createSourceField($type)->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue