function MediaSourceBase::getSourceFieldName
Same name in other branches
- 8.9.x core/modules/media/src/MediaSourceBase.php \Drupal\media\MediaSourceBase::getSourceFieldName()
- 10 core/modules/media/src/MediaSourceBase.php \Drupal\media\MediaSourceBase::getSourceFieldName()
- 11.x core/modules/media/src/MediaSourceBase.php \Drupal\media\MediaSourceBase::getSourceFieldName()
Determine the name of the source field.
Return value
string The source field name. If one is already stored in configuration, it is returned. Otherwise, a new, unused one is generated.
1 call to MediaSourceBase::getSourceFieldName()
- MediaSourceBase::createSourceFieldStorage in core/
modules/ media/ src/ MediaSourceBase.php - Creates the source field storage definition.
2 methods override MediaSourceBase::getSourceFieldName()
- TestDifferentDisplays::getSourceFieldName in core/
modules/ media/ tests/ modules/ media_test_source/ src/ Plugin/ media/ Source/ TestDifferentDisplays.php - Determine the name of the source field.
- TestWithHiddenSourceField::getSourceFieldName in core/
modules/ media/ tests/ modules/ media_test_source/ src/ Plugin/ media/ Source/ TestWithHiddenSourceField.php - Determine the name of the source field.
File
-
core/
modules/ media/ src/ MediaSourceBase.php, line 303
Class
- MediaSourceBase
- Base implementation of media source plugin.
Namespace
Drupal\mediaCode
protected function getSourceFieldName() {
// 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());
$tries = 0;
$storage = $this->entityTypeManager
->getStorage('field_storage_config');
// Iterate at least once, until no field with the generated ID is found.
do {
$id = $base_id;
// If we've tried before, increment and append the suffix.
if ($tries) {
$id .= '_' . $tries;
}
$field = $storage->load('media.' . $id);
$tries++;
} while ($field);
return $id;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.