You are here

public function MediaHelper::getBundlesFromInput in Lightning Media 8.2

Same name and namespace in other branches
  1. 8.4 src/MediaHelper.php \Drupal\lightning_media\MediaHelper::getBundlesFromInput()
  2. 8.3 src/MediaHelper.php \Drupal\lightning_media\MediaHelper::getBundlesFromInput()

Returns the media bundles that can accept an input value.

Parameters

mixed $value: The input value.

bool $check_access: (optional) Whether to filter the bundles by create access for the current user. Defaults to TRUE.

string[] $bundles: (optional) A set of media bundle IDs which might match the input. If omitted, all available bundles are checked.

Return value

\Drupal\media\MediaTypeInterface[] The media bundles that can accept the input value.

1 call to MediaHelper::getBundlesFromInput()
MediaHelper::getBundleFromInput in src/MediaHelper.php
Returns the first media bundle that can accept an input value.

File

src/MediaHelper.php, line 114

Class

MediaHelper
Provides helper methods for dealing with media entities.

Namespace

Drupal\lightning_media

Code

public function getBundlesFromInput($value, $check_access = TRUE, array $bundles = []) {

  // Lightning Media overrides the media_bundle storage handler with a special
  // one that adds an optional second parameter to loadMultiple().
  $media_types = $this->entityTypeManager
    ->getStorage('media_type')
    ->loadMultiple($bundles ?: NULL, $check_access);
  ksort($media_types);
  return array_filter($media_types, function (MediaTypeInterface $media_type) use ($value) {
    $source = $media_type
      ->getSource();
    return $source instanceof InputMatchInterface && $source
      ->appliesTo($value, $media_type);
  });
}