Skip to content

Commit

Permalink
Update DgiImageDiscovery.php
Browse files Browse the repository at this point in the history
  • Loading branch information
prashant-dgi authored Aug 15, 2024
1 parent 80d608d commit 4d4f755
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Plugin/search_api/processor/DgiImageDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
use Drupal\dgi_image_discovery\ImageDiscoveryInterface;
use Drupal\dgi_image_discovery\Plugin\search_api\processor\Property\DgiImageDiscoveryProperty;
use Drupal\dgi_image_discovery\UrlGeneratorPluginManagerInterface;
use Drupal\file\Entity\File;
use Drupal\media\Entity\Media;
use Drupal\node\NodeInterface;
use Drupal\search_api\Datasource\DatasourceInterface;
use Drupal\search_api\Item\ItemInterface;
use Drupal\search_api\Processor\ProcessorPluginBase;
use Drupal\taxonomy\Entity\Term;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand Down Expand Up @@ -158,13 +161,13 @@ protected function getDefaultImageFromTaxonomy(NodeInterface $node, string $imag
$model_terms = $node->get('field_model')->referencedEntities();

foreach ($model_terms as $term) {
if ($term instanceof \Drupal\taxonomy\Entity\Term) {
if ($term instanceof Term) {
// Load the media entity referenced by the field_defaultimage.
$media = $term->get('field_defaultimage')->entity;
if ($media instanceof \Drupal\media\Entity\Media) {
if ($media instanceof Media) {
// Load the file entity from the media entity.
$file = $media->get('field_media_image')->entity;
if ($file instanceof \Drupal\file\Entity\File) {
if ($file instanceof File) {
// Use the provided image style.
$default_image_url = $this->entityTypeManager->getStorage('image_style')->load($image_style_name)
->buildUrl($file->getFileUri());
Expand Down

0 comments on commit 4d4f755

Please sign in to comment.