function FileMediaFormatterBase::isApplicable

Same name in other branches
  1. 8.9.x core/modules/file/src/Plugin/Field/FieldFormatter/FileMediaFormatterBase.php \Drupal\file\Plugin\Field\FieldFormatter\FileMediaFormatterBase::isApplicable()
  2. 10 core/modules/file/src/Plugin/Field/FieldFormatter/FileMediaFormatterBase.php \Drupal\file\Plugin\Field\FieldFormatter\FileMediaFormatterBase::isApplicable()
  3. 11.x core/modules/file/src/Plugin/Field/FieldFormatter/FileMediaFormatterBase.php \Drupal\file\Plugin\Field\FieldFormatter\FileMediaFormatterBase::isApplicable()

Overrides FormatterBase::isApplicable

File

core/modules/file/src/Plugin/Field/FieldFormatter/FileMediaFormatterBase.php, line 75

Class

FileMediaFormatterBase
Base class for media file formatter.

Namespace

Drupal\file\Plugin\Field\FieldFormatter

Code

public static function isApplicable(FieldDefinitionInterface $field_definition) {
    if (!parent::isApplicable($field_definition)) {
        return FALSE;
    }
    
    /** @var \Symfony\Component\Mime\MimeTypeGuesserInterface $extension_mime_type_guesser */
    $extension_mime_type_guesser = \Drupal::service('file.mime_type.guesser.extension');
    $extension_list = array_filter(preg_split('/\\s+/', $field_definition->getSetting('file_extensions')));
    foreach ($extension_list as $extension) {
        if ($extension_mime_type_guesser instanceof MimeTypeGuesserInterface) {
            $mime_type = $extension_mime_type_guesser->guessMimeType('fakedFile.' . $extension);
        }
        else {
            $mime_type = $extension_mime_type_guesser->guess('fakedFile.' . $extension);
            @trigger_error('\\Symfony\\Component\\HttpFoundation\\File\\MimeType\\MimeTypeGuesserInterface is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Implement \\Symfony\\Component\\Mime\\MimeTypeGuesserInterface instead. See https://www.drupal.org/node/3133341', E_USER_DEPRECATED);
        }
        if (static::mimeTypeApplies($mime_type)) {
            return TRUE;
        }
    }
    return FALSE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.