Skip to content

Commit

Permalink
trimmed copy pasta
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Stanley committed Aug 18, 2020
1 parent cbab079 commit a57f131
Showing 1 changed file with 15 additions and 148 deletions.
163 changes: 15 additions & 148 deletions src/Plugin/Action/AbstractGenerateDerivativeMediaFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,10 @@

namespace Drupal\islandora\Plugin\Action;

use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityFieldManager;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\islandora\IslandoraUtils;
use Drupal\islandora\EventGenerator\EmitEvent;
use Drupal\islandora\EventGenerator\EventGeneratorInterface;
use Drupal\islandora\MediaSource\MediaSourceService;
use Drupal\jwt\Authentication\Provider\JwtAuth;
use Drupal\token\Token;
use Stomp\StatefulStomp;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand All @@ -26,28 +17,7 @@
* type = "media"
* )
*/
class AbstractGenerateDerivativeMediaFile extends EmitEvent {

/**
* Islandora utility functions.
*
* @var \Drupal\islandora\IslandoraUtils
*/
protected $utils;

/**
* Media source service.
*
* @var \Drupal\islandora\MediaSource\MediaSourceService
*/
protected $mediaSource;

/**
* Token replacement service.
*
* @var \Drupal\token\Token
*/
protected $token;
class AbstractGenerateDerivativeMediaFile extends AbstractGenerateDerivative {

/**
* The entity field manager.
Expand All @@ -57,81 +27,25 @@ class AbstractGenerateDerivativeMediaFile extends EmitEvent {
protected $entityFieldManager;

/**
* 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\islandora\IslandoraUtils $utils
* Islandora utility functions.
* @param \Drupal\islandora\MediaSource\MediaSourceService $media_source
* Media source service.
* @param \Drupal\token\Token $token
* Token service.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* Field Manager service.
* {@inheritdoc}
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
AccountInterface $account,
EntityTypeManager $entity_type_manager,
EventGeneratorInterface $event_generator,
StatefulStomp $stomp,
JwtAuth $auth,
IslandoraUtils $utils,
MediaSourceService $media_source,
Token $token,
EntityFieldManagerInterface $entity_field_manager
) {
parent::__construct(
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create(
$container,
$configuration,
$plugin_id,
$plugin_definition,
$account,
$entity_type_manager,
$event_generator,
$stomp,
$auth
$plugin_definition
);
$this->utils = $utils;
$this->mediaSource = $media_source;
$this->token = $token;
$this->entityFieldManager = $entity_field_manager;
$instance->setEntityFieldManager($container->get('entity_field.manager'));
return $instance;

}

/**
* {@inheritdoc}
* Sets EntityFieldManager.
*/
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('islandora.utils'),
$container->get('islandora.media_source_service'),
$container->get('token'),
$container->get('entity_field.manager')
);
public function setEntityFieldManager(EntityFieldManager $entityFieldManager) {
$this->entityFieldManager = $entityFieldManager;
}

/**
Expand Down Expand Up @@ -179,7 +93,8 @@ protected function generateData(EntityInterface $entity) {
];
$path = $this->token->replace($data['path'], $token_data);
$data['file_upload_uri'] = $data['scheme'] . '://' . $path;
$allowed = ['queue',
$allowed = [
'queue',
'event',
'args',
'source_uri',
Expand Down Expand Up @@ -255,29 +170,6 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
return $form;
}

/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::validateConfigurationForm($form, $form_state);

$exploded_mime = explode('/', $form_state->getValue('mimetype'));

if (count($exploded_mime) != 2) {
$form_state->setErrorByName(
'mimetype',
t('Please enter a mimetype (e.g. image/jpeg, video/mp4, audio/mp3, etc...)')
);
}

if (empty($exploded_mime[1])) {
$form_state->setErrorByName(
'mimetype',
t('Please enter a mimetype (e.g. image/jpeg, video/mp4, audio/mp3, etc...)')
);
}
}

/**
* {@inheritdoc}
*/
Expand All @@ -290,29 +182,4 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
$this->configuration['destination_field_name'] = $form_state->getValue('destination_field_name');
}

/**
* Find a media_type by id and return it or nothing.
*
* @param string $entity_id
* The media type.
*
* @return \Drupal\Core\Entity\EntityInterface|string
* Return the loaded entity or nothing.
*
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* Thrown by getStorage() if the entity type doesn't exist.
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* Thrown by getStorage() if the storage handler couldn't be loaded.
*/
protected function getEntityById($entity_id) {
$entity_ids = $this->entityTypeManager->getStorage('media_type')
->getQuery()->condition('id', $entity_id)->execute();

$id = reset($entity_ids);
if ($id !== FALSE) {
return $this->entityTypeManager->getStorage('media_type')->load($id);
}
return '';
}

}

0 comments on commit a57f131

Please sign in to comment.