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 1 commit
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
41 changes: 21 additions & 20 deletions src/Plugin/OaiMetadataMap/DgiStandard.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Drupal\Core\Field\EntityReferenceFieldItemListInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\dgi_image_discovery\ImageDiscovery;
use Drupal\entity_reference_revisions\EntityReferenceRevisionsFieldItemList;
use Drupal\islandora\IslandoraUtils;
Expand Down Expand Up @@ -164,6 +164,13 @@ class DgiStandard extends OaiMetadataMapBase implements ContainerFactoryPluginIn
*/
protected ImageDiscovery $imageDiscovery;

/**
* The URL generator.
*
* @var \Drupal\Core\Routing\UrlGeneratorInterface
*/
protected UrlGeneratorInterface $urlGenerator;

/**
* {@inheritdoc}
*/
Expand All @@ -174,6 +181,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('url_generator');
return $plugin;
}

Expand Down Expand Up @@ -393,25 +401,18 @@ public function addThumbnail(ContentEntityInterface $entity, $dest) {
$event = $this->imageDiscovery->getImage($entity);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is still doing an unnecessary lookup. Why bother keeping this if doing the deferred resolution, which expects to handle the lookup separately?


if ($event->hasMedia()) {
$media = $event->getMedia();

$fid = $media->getSource()->getSourceFieldValue($media);
$file = $this->entityTypeManager->getStorage('file')->load($fid);

if ($file) {
$style_id = 'solr_grid_thumbnail';
$node_id = $entity->id();

// Generate the deferred resolution URL.
$url = Url::fromRoute('dgi_image_discovery.deferred_resolution', [
'node' => $node_id,
'style' => $style_id,
])->setAbsolute(TRUE);

$resolved_image_url = $url->toString();

// Add the resolved image URL to the elements array.
$this->elements[$dest][] = $resolved_image_url;
$style_id = 'solr_grid_thumbnail';
$node_id = $entity->id();

// Use the URL generator to create the deferred resolution URL.
$url = $this->urlGenerator->generateFromRoute('dgi_image_discovery.deferred_resolution', [
'node' => $node_id,
'style' => $style_id,
], ['absolute' => TRUE]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not the intended URL Generator plugin (is this service even plugin based? Dunno)? Like, was meaning the plugins for the image discovery, in https://github.com/discoverygarden/dgi_image_discovery/tree/main/src/Plugin/dgi_image_discovery/url_generator

... so, using the related plugin manager and getting an instance of the desired plugin. Not sure if it's necessary here to make it fully configurable, but could? Not much configuration on either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@adam-vessey I made code changes, please review.


// Add the resolved image URL to the elements array.
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