diff --git a/islandora.services.yml b/islandora.services.yml index 0ba96794..fb7026bf 100644 --- a/islandora.services.yml +++ b/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] diff --git a/src/EventGenerator/EventGenerator.php b/src/EventGenerator/EventGenerator.php index df258b6b..ac258163 100644 --- a/src/EventGenerator/EventGenerator.php +++ b/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'; } diff --git a/src/Flysystem/Fedora.php b/src/Flysystem/Fedora.php index fd347b89..85f42b1a 100644 --- a/src/Flysystem/Fedora.php +++ b/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, diff --git a/tests/src/Kernel/EventGeneratorTest.php b/tests/src/Kernel/EventGeneratorTest.php index 9f0bed06..c5703f3f 100644 --- a/tests/src/Kernel/EventGeneratorTest.php +++ b/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')); } /** diff --git a/tests/src/Kernel/FedoraPluginTest.php b/tests/src/Kernel/FedoraPluginTest.php index 8f85251b..67491507 100644 --- a/tests/src/Kernel/FedoraPluginTest.php +++ b/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); } /** diff --git a/tests/src/Kernel/IslandoraKernelTestBase.php b/tests/src/Kernel/IslandoraKernelTestBase.php index 5690bc1f..5a95cb68 100644 --- a/tests/src/Kernel/IslandoraKernelTestBase.php +++ b/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'); } }