112 lines
3.1 KiB
112 lines
3.1 KiB
<?php |
|
|
|
namespace Drupal\islandora\Plugin\Action; |
|
|
|
use Drupal\Core\Entity\EntityInterface; |
|
use Drupal\Core\Entity\EntityTypeManager; |
|
use Drupal\Core\File\FileSystem; |
|
use Drupal\Core\Session\AccountInterface; |
|
use Drupal\Core\Site\Settings; |
|
use Drupal\jwt\Authentication\Provider\JwtAuth; |
|
use Drupal\islandora\EventGenerator\EmitEvent; |
|
use Drupal\islandora\EventGenerator\EventGeneratorInterface; |
|
use Stomp\StatefulStomp; |
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
|
/** |
|
* Emits a File event. |
|
* |
|
* @Action( |
|
* id = "emit_file_event", |
|
* label = @Translation("Emit a file event to a queue/topic"), |
|
* type = "file" |
|
* ) |
|
*/ |
|
class EmitFileEvent extends EmitEvent { |
|
|
|
/** |
|
* File system service. |
|
* |
|
* @var \Drupal\Core\File\FileSystem |
|
*/ |
|
protected $fileSystem; |
|
|
|
/** |
|
* Constructs a EmitEvent action. |
|
* |
|
* @param array $configuration |
|
* A configuration array containing information about the plugin instance. |
|
* @param string $plugin_id |
|
* The plugin_id for the plugin instance. |
|
* @param mixed $plugin_definition |
|
* The plugin implementation definition. |
|
* @param \Drupal\Core\Session\AccountInterface $account |
|
* Current user. |
|
* @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager |
|
* Entity type manager. |
|
* @param \Drupal\islandora\EventGenerator\EventGeneratorInterface $event_generator |
|
* EventGenerator service to serialize AS2 events. |
|
* @param \Stomp\StatefulStomp $stomp |
|
* Stomp client. |
|
* @param \Drupal\jwt\Authentication\Provider\JwtAuth $auth |
|
* JWT Auth client. |
|
* @param \Drupal\Core\File\FileSystem $file_system |
|
* File system service. |
|
*/ |
|
public function __construct( |
|
array $configuration, |
|
$plugin_id, |
|
$plugin_definition, |
|
AccountInterface $account, |
|
EntityTypeManager $entity_type_manager, |
|
EventGeneratorInterface $event_generator, |
|
StatefulStomp $stomp, |
|
JwtAuth $auth, |
|
FileSystem $file_system |
|
) { |
|
parent::__construct( |
|
$configuration, |
|
$plugin_id, |
|
$plugin_definition, |
|
$account, |
|
$entity_type_manager, |
|
$event_generator, |
|
$stomp, |
|
$auth |
|
); |
|
$this->fileSystem = $file_system; |
|
} |
|
|
|
/** |
|
* {@inheritdoc} |
|
*/ |
|
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { |
|
return new static( |
|
$configuration, |
|
$plugin_id, |
|
$plugin_definition, |
|
$container->get('current_user'), |
|
$container->get('entity_type.manager'), |
|
$container->get('islandora.eventgenerator'), |
|
$container->get('islandora.stomp'), |
|
$container->get('jwt.authentication.jwt'), |
|
$container->get('file_system') |
|
); |
|
} |
|
|
|
/** |
|
* {@inheritdoc} |
|
*/ |
|
protected function generateData(EntityInterface $entity) { |
|
$uri = $entity->getFileUri(); |
|
$scheme = $this->fileSystem->uriScheme($uri); |
|
$flysystem_config = Settings::get('flysystem'); |
|
|
|
$data = parent::generateData($entity); |
|
if (isset($flysystem_config[$scheme]) && $flysystem_config[$scheme]['driver'] == 'fedora') { |
|
$data['fedora_uri'] = str_replace("$scheme://", $flysystem_config[$scheme]['config']['root'], $uri); |
|
} |
|
return $data; |
|
} |
|
|
|
}
|
|
|