Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDST-554: New roles added to Creator vs Contributor mapping #16

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions src/Plugin/OaiMetadataMap/DgiStandard.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\EntityReferenceFieldItemListInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\GeneratedUrl;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\image\ImageStyleInterface;
use Drupal\dgi_image_discovery\ImageDiscovery;
use Drupal\entity_reference_revisions\EntityReferenceRevisionsFieldItemList;
use Drupal\islandora\IslandoraUtils;
Expand Down Expand Up @@ -137,6 +139,9 @@ class DgiStandard extends OaiMetadataMapBase implements ContainerFactoryPluginIn
'relators:spk' => 'dcterms:contributor',
'relators:spn' => 'dcterms:contributor',
'realtors:vdg' => 'dcterms:contributor',
'relators:art' => 'dcterms:creator',
'relators:ill' => 'dcterms:contributor',
'relators:trl' => 'dcterms:contributor',
];

/**
Expand All @@ -160,6 +165,13 @@ class DgiStandard extends OaiMetadataMapBase implements ContainerFactoryPluginIn
*/
protected ImageDiscovery $imageDiscovery;

/**
* The URL generator.
*
* @var \Drupal\dgi_image_discovery\UrlGeneratorPluginBase
*/
protected $urlGenerator;

/**
* {@inheritdoc}
*/
Expand All @@ -170,6 +182,7 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin->entityTypeManager = $container->get('entity_type.manager');
$plugin->utils = $container->get('islandora.utils');
$plugin->imageDiscovery = $container->get('dgi_image_discovery.service');
$plugin->urlGenerator = $container->get('plugin.manager.dgi_image_discovery.url_generator')->createInstance('deferred');
return $plugin;
}

Expand Down Expand Up @@ -386,14 +399,22 @@ protected function addPersistentUrl(ContentEntityInterface $entity, $dest, $alia
* The destination index for the thumbnail.
*/
public function addThumbnail(ContentEntityInterface $entity, $dest) {
$event = $this->imageDiscovery->getImage($entity);
$style_id = 'solr_grid_thumbnail';

// Load the image style.
$style = $this->entityTypeManager->getStorage('image_style')->load($style_id);

if ($event->hasMedia()) {
$media = $event->getMedia();
if ($style instanceof ImageStyleInterface) {
// Generate the URL using the Deferred plugin.
$generated_url = $this->urlGenerator->generate($entity, $style);

$fid = $media->getSource()->getSourceFieldValue($media);
$file = $this->entityTypeManager->getStorage('file')->load($fid);
$this->elements[$dest][] = $file->createFileUrl(FALSE);
// Add the resolved image URL to the elements array.
if ($generated_url instanceof GeneratedUrl) {
$url = $generated_url->getGeneratedUrl();
if (!empty($url)) {
$this->elements[$dest][] = $url;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this was already setting a thumbnail?

... but it's doing an up-front lookup just to use the deferred thing? Should probably drop the up-front lookup to just always do the deferred thing?

Kinda want to suggest making use of the URL generator plugins, instead of directly using the underlying route.

}

Expand Down
Loading