You are here

public function OpenerResolver::get in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/media_library/src/OpenerResolver.php \Drupal\media_library\OpenerResolver::get()
  2. 10 core/modules/media_library/src/OpenerResolver.php \Drupal\media_library\OpenerResolver::get()

Gets a media library opener service from the container.

Parameters

\Drupal\media_library\MediaLibraryState $state: A value object representing the state of the media library.

Return value

\Drupal\media_library\MediaLibraryOpenerInterface The media library opener service.

Throws

\RuntimeException If the requested opener service does not implement \Drupal\media_library\MediaLibraryOpenerInterface.

Overrides OpenerResolverInterface::get

File

core/modules/media_library/src/OpenerResolver.php, line 26

Class

OpenerResolver
Defines a class to get media library openers from the container.

Namespace

Drupal\media_library

Code

public function get(MediaLibraryState $state) {
  $service_id = $state
    ->getOpenerId();
  $service = $this->container
    ->get($service_id);
  if ($service instanceof MediaLibraryOpenerInterface) {
    return $service;
  }
  throw new \RuntimeException("{$service_id} must be an instance of " . MediaLibraryOpenerInterface::class);
}