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:
islandora.eventgenerator:
class: Drupal\islandora\EventGenerator\EventGenerator
arguments: ['@language_manager']
islandora.stomp:
class: Stomp\StatefulStomp
factory: ['Drupal\islandora\StompFactory', create]

30
src/EventGenerator/EventGenerator.php

@ -3,7 +3,8 @@
namespace Drupal\islandora\EventGenerator;
use Drupal\Core\Entity\EntityInterface;
use Drupal\file\FileInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Url;
use Drupal\user\UserInterface;
/**
@ -13,19 +14,42 @@ use Drupal\user\UserInterface;
*/
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}
*/
public function generateEvent(EntityInterface $entity, UserInterface $user, array $data) {
$user_url = $user->toUrl()->setAbsolute()->toString();
$entity_type = $entity->getEntityTypeId();
if ($entity instanceof FileInterface) {
if ($entity_type == 'file') {
$entity_url = $entity->url();
$mimetype = $entity->getMimeType();
}
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';
}

19
src/Flysystem/Fedora.php

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

2
tests/src/Kernel/EventGeneratorTest.php

@ -64,7 +64,7 @@ class EventGeneratorTest extends IslandoraKernelTestBase {
$this->entity->save();
// 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();
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('file');
$this->installConfig('filter');
$this->installConfig('rest');
}
}

Loading…
Cancel
Save