public function MediaDirectoriesUiHelper::getValidExtensions in Media Directories 2.x
Same name and namespace in other branches
- 8 modules/media_directories_ui/src/MediaDirectoriesUiHelper.php \Drupal\media_directories_ui\MediaDirectoriesUiHelper::getValidExtensions()
Collect all supported extensions.
Return value
string Valid file extensions separated by comma.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
File
- modules/
media_directories_ui/ src/ MediaDirectoriesUiHelper.php, line 94
Class
- MediaDirectoriesUiHelper
- Media directories UI helper service.
Namespace
Drupal\media_directories_uiCode
public function getValidExtensions() {
$valid_extensions = [];
$combined_media_types = $this->settings
->get('combined_upload_media_types');
/** @var \Drupal\media\Entity\MediaType[] $types */
$types = $this->entityTypeManager
->getStorage('media_type')
->loadMultiple();
foreach ($types as $type) {
if (!in_array($type
->id(), $combined_media_types, TRUE)) {
continue;
}
$source_field = $type
->getSource()
->getConfiguration()['source_field'];
$field_config = $this->entityTypeManager
->getStorage('field_config')
->load('media.' . $type
->id() . '.' . $source_field);
$valid_extensions = array_merge($valid_extensions, explode(' ', $field_config
->getSetting('file_extensions')));
}
$valid_extensions = array_unique($valid_extensions);
return implode(' ', $valid_extensions);
}