From a57f131fddef81937fc726a58aa570538a621ed3 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Tue, 18 Aug 2020 16:35:21 +0000 Subject: [PATCH] trimmed copy pasta --- .../AbstractGenerateDerivativeMediaFile.php | 163 ++---------------- 1 file changed, 15 insertions(+), 148 deletions(-) diff --git a/src/Plugin/Action/AbstractGenerateDerivativeMediaFile.php b/src/Plugin/Action/AbstractGenerateDerivativeMediaFile.php index 9b20eb1e9..712dbe1ae 100644 --- a/src/Plugin/Action/AbstractGenerateDerivativeMediaFile.php +++ b/src/Plugin/Action/AbstractGenerateDerivativeMediaFile.php @@ -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; /** @@ -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. @@ -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; } /** @@ -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', @@ -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} */ @@ -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 ''; - } - }