Browse Source

Forcing urls in event messages to be language neutral as well (#141)

pull/729/head
dannylamb 6 years ago committed by Natkeeran
parent
commit
578ab47fd9
  1. 1
      islandora.services.yml
  2. 30
      src/EventGenerator/EventGenerator.php
  3. 19
      src/Flysystem/Fedora.php
  4. 2
      tests/src/Kernel/EventGeneratorTest.php
  5. 4
      tests/src/Kernel/FedoraPluginTest.php
  6. 1
      tests/src/Kernel/IslandoraKernelTestBase.php

1
islandora.services.yml

@ -3,6 +3,7 @@
services: services:
islandora.eventgenerator: islandora.eventgenerator:
class: Drupal\islandora\EventGenerator\EventGenerator class: Drupal\islandora\EventGenerator\EventGenerator
arguments: ['@language_manager']
islandora.stomp: islandora.stomp:
class: Stomp\StatefulStomp class: Stomp\StatefulStomp
factory: ['Drupal\islandora\StompFactory', create] factory: ['Drupal\islandora\StompFactory', create]

30
src/EventGenerator/EventGenerator.php

@ -3,7 +3,8 @@
namespace Drupal\islandora\EventGenerator; namespace Drupal\islandora\EventGenerator;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\file\FileInterface; use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Url;
use Drupal\user\UserInterface; use Drupal\user\UserInterface;
/** /**
@ -13,19 +14,42 @@ use Drupal\user\UserInterface;
*/ */
class EventGenerator implements EventGeneratorInterface { class EventGenerator implements EventGeneratorInterface {
/**
* Language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* Constructor.
*
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* Language manager.
*/
public function __construct(LanguageManagerInterface $language_manager) {
$this->languageManager = $language_manager;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function generateEvent(EntityInterface $entity, UserInterface $user, array $data) { public function generateEvent(EntityInterface $entity, UserInterface $user, array $data) {
$user_url = $user->toUrl()->setAbsolute()->toString(); $user_url = $user->toUrl()->setAbsolute()->toString();
$entity_type = $entity->getEntityTypeId();
if ($entity instanceof FileInterface) { if ($entity_type == 'file') {
$entity_url = $entity->url(); $entity_url = $entity->url();
$mimetype = $entity->getMimeType(); $mimetype = $entity->getMimeType();
} }
else { else {
$entity_url = $entity->toUrl()->setAbsolute()->toString(); $undefined = $this->languageManager->getLanguage('und');
$entity_url = Url::fromRoute(
"rest.entity.$entity_type.GET",
[$entity_type => $entity->id()],
['absolute' => TRUE, 'language' => $undefined]
)->toString();
$mimetype = 'text/html'; $mimetype = 'text/html';
} }

19
src/Flysystem/Fedora.php

@ -2,6 +2,7 @@
namespace Drupal\islandora\Flysystem; namespace Drupal\islandora\Flysystem;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Logger\RfcLogLevel; use Drupal\Core\Logger\RfcLogLevel;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
@ -30,6 +31,13 @@ class Fedora implements FlysystemPluginInterface, ContainerFactoryPluginInterfac
protected $mimeTypeGuesser; protected $mimeTypeGuesser;
/**
* Language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/** /**
* Constructs a Fedora plugin for Flysystem. * Constructs a Fedora plugin for Flysystem.
* *
@ -37,13 +45,17 @@ class Fedora implements FlysystemPluginInterface, ContainerFactoryPluginInterfac
* Fedora client. * Fedora client.
* @param \Symfony\Component\HttpFoundation\File\Mimetype\MimeTypeGuesserInterface $mime_type_guesser * @param \Symfony\Component\HttpFoundation\File\Mimetype\MimeTypeGuesserInterface $mime_type_guesser
* Mimetype guesser. * Mimetype guesser.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* Language manager.
*/ */
public function __construct( public function __construct(
IFedoraApi $fedora, IFedoraApi $fedora,
MimeTypeGuesserInterface $mime_type_guesser MimeTypeGuesserInterface $mime_type_guesser,
LanguageManagerInterface $language_manager
) { ) {
$this->fedora = $fedora; $this->fedora = $fedora;
$this->mimeTypeGuesser = $mime_type_guesser; $this->mimeTypeGuesser = $mime_type_guesser;
$this->languageManager = $language_manager;
} }
/** /**
@ -63,7 +75,8 @@ class Fedora implements FlysystemPluginInterface, ContainerFactoryPluginInterfac
// Return it. // Return it.
return new static( return new static(
$fedora, $fedora,
$container->get('file.mime_type.guesser') $container->get('file.mime_type.guesser'),
$container->get('language_manager')
); );
} }
@ -129,7 +142,7 @@ class Fedora implements FlysystemPluginInterface, ContainerFactoryPluginInterfac
]; ];
// Force file urls to be language neutral. // Force file urls to be language neutral.
$undefined = \Drupal::languageManager()->getLanguage('und'); $undefined = $this->languageManager->getLanguage('und');
return Url::fromRoute( return Url::fromRoute(
'flysystem.serve', 'flysystem.serve',
$arguments, $arguments,

2
tests/src/Kernel/EventGeneratorTest.php

@ -64,7 +64,7 @@ class EventGeneratorTest extends IslandoraKernelTestBase {
$this->entity->save(); $this->entity->save();
// Create the event generator so we can test it. // Create the event generator so we can test it.
$this->eventGenerator = new EventGenerator(); $this->eventGenerator = new EventGenerator($this->container->get('language_manager'));
} }
/** /**

4
tests/src/Kernel/FedoraPluginTest.php

@ -31,7 +31,9 @@ class FedoraPluginTest extends IslandoraKernelTestBase {
$mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class)->reveal(); $mime_guesser = $this->prophesize(MimeTypeGuesserInterface::class)->reveal();
return new Fedora($api, $mime_guesser); $language_manager = $this->container->get('language_manager');
return new Fedora($api, $mime_guesser, $language_manager);
} }
/** /**

1
tests/src/Kernel/IslandoraKernelTestBase.php

@ -54,6 +54,7 @@ abstract class IslandoraKernelTestBase extends KernelTestBase {
$this->installEntitySchema('context'); $this->installEntitySchema('context');
$this->installEntitySchema('file'); $this->installEntitySchema('file');
$this->installConfig('filter'); $this->installConfig('filter');
$this->installConfig('rest');
} }
} }

Loading…
Cancel
Save