public function getFileExtensions($check_access = FALSE, array $bundles = []) {
    $extensions = '';

    // GovCMS Media overrides the media_bundle storage handler with a special
    // one that adds an optional second parameter to loadMultiple().
    $storage = $this->entityTypeManager
      ->getStorage('media_type');
    $media_types = $storage->loadMultiple($bundles ?: NULL, $check_access);

    /** @var \Drupal\media\MediaTypeInterface $media_type */
    foreach ($media_types as $media_type) {
      $field = $media_type->getSource()->getSourceFieldDefinition($media_type);

      // If the field is a FileItem or any of its descendants, we can consider
      // it a file field. This will automatically include things like image
      // fields, which extend file fields.
      if (is_a($field->getItemDefinition()->getClass(), FileItem::class, TRUE)) {
        $extensions .= $field->getSetting('file_extensions') . ' ';
      }
    }
    $extensions = preg_split('/,?\s+/', rtrim($extensions));
    return array_unique($extensions);
  }
public function getFileExtensions($check_access = FALSE, array $bundles = []) {
    $extensions = '';

    // GovCMS Media overrides the media_bundle storage handler with a special
    // one that adds an optional second parameter to loadMultiple().
    $storage = $this->entityTypeManager
      ->getStorage('media_type');
    $media_types = $storage->loadMultiple($bundles ?: NULL, $check_access);

    /** @var \Drupal\media\MediaTypeInterface $media_type */
    foreach ($media_types as $media_type) {
      $field = $media_type->getSource()->getSourceFieldDefinition($media_type);

      // If the field is a FileItem or any of its descendants, we can consider
      // it a file field. This will automatically include things like image
      // fields, which extend file fields.
      if (is_a($field->getItemDefinition()->getClass(), FileItem::class, TRUE)) {
        $extensions .= $field->getSetting('file_extensions') . ' ';
      }
    }
    $extensions = preg_split('/,?\s+/', rtrim($extensions));
    return array_unique($extensions);
  }
public function getFileExtensions ( $ check_access = FALSE , array $ bundles = [ ] ) { $ extensions = '' ; // GovCMS Media overrides the media_bundle storage handler with a special // one that adds an optional second parameter to loadMultiple(). $ storage = $ this -> entityTypeManager -> getStorage ( 'media_type' ) ; $ media_types = $ storage -> loadMultiple ( $ bundles ? : NULL , $ check_access ) ; /** @var \Drupal\media\MediaTypeInterface $media_type */ foreach ( $ media_types as $ media_type ) { $ field = $ media_type -> getSource ( ) -> getSourceFieldDefinition ( $ media_type ) ; // If the field is a FileItem or any of its descendants, we can consider // it a file field. This will automatically include things like image // fields, which extend file fields. if ( is_a ( $ field -> getItemDefinition ( ) -> getClass ( ) , FileItem :: class , TRUE ) ) { $ extensions .= $ field -> getSetting ( 'file_extensions' ) . ' ' ; } } $ extensions = preg_split ( '/,?\s+/' , rtrim ( $ extensions ) ) ; return array_unique ( $ extensions ) ; }
Returns all file extensions accepted by bundles that use file fields.

@param bool $check_access
(optional) Whether to filter the bundles by create access for the current
user. Defaults to FALSE.
@param string[] $bundles
(optional) An array of bundle IDs from which to retrieve source field
extensions. If omitted, all available bundles are allowed.

@return string[]
The file extensions accepted by all available bundles.
Returns all file extensions accepted by bundles that use file fields .