Loading core/modules/media/src/MediaSourceBase.php +6 −1 Original line number Diff line number Diff line Loading @@ -301,9 +301,14 @@ public function createSourceField(MediaTypeInterface $type) { * 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'); Loading core/modules/media/tests/src/Kernel/MediaSourceTest.php +23 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,11 @@ */ class MediaSourceTest extends MediaKernelTestBase { /** * {@inheritdoc} */ protected static $modules = ['field_ui']; /** * Tests that metadata is correctly mapped irrespective of how media is saved. */ Loading Loading @@ -506,6 +511,24 @@ public function testSourceFieldCreation() { $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 Loading
core/modules/media/src/MediaSourceBase.php +6 −1 Original line number Diff line number Diff line Loading @@ -301,9 +301,14 @@ public function createSourceField(MediaTypeInterface $type) { * 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'); Loading
core/modules/media/tests/src/Kernel/MediaSourceTest.php +23 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,11 @@ */ class MediaSourceTest extends MediaKernelTestBase { /** * {@inheritdoc} */ protected static $modules = ['field_ui']; /** * Tests that metadata is correctly mapped irrespective of how media is saved. */ Loading Loading @@ -506,6 +511,24 @@ public function testSourceFieldCreation() { $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