Skip to content

Commit

Permalink
Merge pull request #10 from discoverygarden/fix/avoid-tagging
Browse files Browse the repository at this point in the history
CTDA9-490: Attempt to avoid tagging.
  • Loading branch information
nchiasson-dgi authored Sep 6, 2023
2 parents a4c1f9a + e2305bc commit 6ede165
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/Plugin/search_api/processor/HOCRField.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\islandora_hocr\Plugin\search_api\processor;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\file\FileInterface;
use Drupal\islandora_hocr\Plugin\search_api\processor\Property\HOCRFieldProperty;
use Drupal\media\Plugin\media\Source\File;
Expand Down Expand Up @@ -147,26 +148,39 @@ protected function getFile(NodeInterface $node) : ?FileInterface {

$query->condition('field_media_of', $node->id());
$query->condition('field_media_use.entity:taxonomy_term.field_external_uri.uri', 'https://discoverygarden.ca/use#hocr');
$query->accessCheck(FALSE);

$media = $query->execute();

$medium = reset($media);
if (!$medium) {
return NULL;
}
$anonymous = new AnonymousUserSession();

/** @var \Drupal\media\MediaInterface $entity */
$entity = $media_storage->load($medium);
if (!$entity) {
return NULL;
}
foreach ($media as $medium) {
/** @var \Drupal\media\MediaInterface $entity */
$entity = $media_storage->load($medium);
if (!$entity) {
continue;
}
elseif (!$entity->access('view', $anonymous, FALSE)) {
continue;
}

$source = $entity->getSource();

$source = $entity->getSource();
if ($source instanceof File) {
$fid = $source->getSourceFieldValue($entity);
/** @var \Drupal\file\FileInterface $file */
$file = $this->entityTypeManager->getStorage('file')->load($fid);

if ($source instanceof File) {
$fid = $source->getSourceFieldValue($entity);
return $this->entityTypeManager->getStorage('file')->load($fid);
if (!$file->access('view', $anonymous, FALSE)) {
continue;
}

return $file;
}
}

// Failed to find anything applicable/visible.
return NULL;
}

}

0 comments on commit 6ede165

Please sign in to comment.