Skip to content

Commit

Permalink
DDST-922 : WIP (#34)
Browse files Browse the repository at this point in the history
* Refactor WIP.

* Modifying field_default_image retrieval.

* Removing development statements.

* Coding standards.
  • Loading branch information
MorganDawe authored Jan 7, 2025
1 parent 8d1a6c8 commit a344528
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/EventSubscriber/ModelDefaultFallbackSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,25 @@ public function discoverImage(ImageDiscoveryEvent $event) : void {
/** @var \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem $term_item */
foreach ($entity->get('field_model') as $term_item) {
/** @var \Drupal\taxonomy\TermInterface $term */
$term = $term_item?->get('entity')?->getTarget();
$term = $term_item?->get('entity')?->getTarget()?->getEntity();
$term_access = $term?->access('view', NULL, TRUE);

if (!$term_access?->isAllowed()) {
continue;
}

if (!$term?->hasField('field_default_image')) {
continue;
}

/** @var \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem $candidate_item */
foreach ($term->get('field_default_image') as $candidate_item) {
/** @var \Drupal\media\MediaInterface $candidate */
if (!$candidate = $candidate_item?->get('entity')?->getTarget()) {

/** @var \Drupal\media\Entity\Media $candidate */
if (!$candidate = $candidate_item?->get('entity')?->getTarget()?->getEntity()) {
continue;
}

$candidate_access = $candidate?->access('view', NULL, TRUE);
if (!$candidate_access->isAllowed()) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Field/FieldType/DIDImageItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DIDImageItem extends EntityReferenceItem implements RefinableCacheableDepe
public function __construct(
DataDefinitionInterface $definition,
$name = NULL,
TypedDataInterface $parent = NULL,
?TypedDataInterface $parent = NULL,
) {
parent::__construct($definition, $name, $parent);

Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/search_api/processor/DgiImageDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* {@inheritdoc}
*/
public function getPropertyDefinitions(DatasourceInterface $datasource = NULL) {
public function getPropertyDefinitions(?DatasourceInterface $datasource = NULL) {
$properties = [];

if (!$datasource) {
Expand Down

0 comments on commit a344528

Please sign in to comment.