class MediaSelectionProcessorManager in Gutenberg 8.2
Same name and namespace in other branches
- 8 src/MediaSelectionProcessor/MediaSelectionProcessorManager.php \Drupal\gutenberg\MediaSelectionProcessor\MediaSelectionProcessorManager
Provides management for tagged media selection processor services.
@package Drupal\gutenberg\MediaSelectionProcessor
Hierarchy
- class \Drupal\gutenberg\MediaSelectionProcessor\MediaSelectionProcessorManager implements MediaSelectionProcessorManagerInterface
Expanded class hierarchy of MediaSelectionProcessorManager
1 string reference to 'MediaSelectionProcessorManager'
1 service uses MediaSelectionProcessorManager
File
- src/
MediaSelectionProcessor/ MediaSelectionProcessorManager.php, line 10
Namespace
Drupal\gutenberg\MediaSelectionProcessorView source
class MediaSelectionProcessorManager implements MediaSelectionProcessorManagerInterface {
/**
* List of registered processors for media library selections.
*
* @var MediaSelectionProcessorInterface[]
*/
protected $processors = [];
/**
* {@inheritDoc}
*/
public function registerProcessor(MediaSelectionProcessorInterface $processor, string $processor_name) {
if ($this
->isRegistered($processor_name)) {
throw new \Exception(sprintf("Processor '%s' has been already registered", $processor_name));
}
$this->processors[$processor_name] = $processor;
}
/**
* {@inheritDoc}
*/
public function process(string $processor_name, array $data) {
if (!$this
->isRegistered($processor_name)) {
throw new \Exception(sprintf("Processor '%s' is not registered", $processor_name));
}
return $this->processors[$processor_name]
->process($data);
}
/**
* {@inheritDoc}
*/
public function processData(string $data) {
$media_entities = [];
if (is_numeric($data)) {
$media_entities = $this
->process('default', [
$data,
]);
}
else {
$special_data = json_decode($data, TRUE);
foreach ($special_data as $processor => $processor_data) {
$media_entities = $this
->process($processor, $processor_data);
}
}
return $media_entities;
}
/**
* Check if media selection processor is registered in the manager.
*
* @param string $processor_name
* Name of media selection processor.
*
* @return bool
* TRUE if the specified processor type exists, FALSE otherwise.
*/
public function isRegistered(string $processor_name) {
return array_key_exists($processor_name, $this->processors);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MediaSelectionProcessorManager:: |
protected | property | List of registered processors for media library selections. | |
MediaSelectionProcessorManager:: |
public | function | Check if media selection processor is registered in the manager. | |
MediaSelectionProcessorManager:: |
public | function |
Process media selection data by provided processor. Overrides MediaSelectionProcessorManagerInterface:: |
|
MediaSelectionProcessorManager:: |
public | function |
Process selection data. Overrides MediaSelectionProcessorManagerInterface:: |
|
MediaSelectionProcessorManager:: |
public | function |
Register media selection processor. Overrides MediaSelectionProcessorManagerInterface:: |