You are here

protected function FileUpload::isAllowedType in Lightning Media 8.4

Same name and namespace in other branches
  1. 8.3 src/Plugin/EntityBrowser/Widget/FileUpload.php \Drupal\lightning_media\Plugin\EntityBrowser\Widget\FileUpload::isAllowedType()

Tests if a media type can be used by this widget.

Parameters

\Drupal\media\MediaTypeInterface $media_type: The media type.

Return value

bool TRUE if the media type can be used, FALSE otherwise.

Overrides EntityFormProxy::isAllowedType

File

src/Plugin/EntityBrowser/Widget/FileUpload.php, line 246

Class

FileUpload
An Entity Browser widget for creating media entities from uploaded files.

Namespace

Drupal\lightning_media\Plugin\EntityBrowser\Widget

Code

protected function isAllowedType(MediaTypeInterface $media_type) {
  $is_allowed = parent::isAllowedType($media_type);
  if ($is_allowed) {
    $item_class = $media_type
      ->getSource()
      ->getSourceFieldDefinition($media_type)
      ->getItemDefinition()
      ->getClass();
    $is_allowed = is_a($item_class, FileItem::class, TRUE);
  }
  return $is_allowed;
}