Spin off from #2913523: Order item referencing addon entity breaks order item Views integration. Minor as its an edge case.

OrderItemViewsData builds a relationship dynamically from the order item to the purchasable entity type based on the order item type's purchasable entity.

    // Provide a relationship for each entity type found.
    foreach ($entity_type_ids as $entity_type_id) {
      /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
      $entity_type = $this->entityManager->getDefinition($entity_type_id);

This line of code breaks, however, if that entity has disappeared and Drupal didn't remove the order item type configuration.

We need to add a `hasDefinition` check before assuming the definition exists.

Comments

mglaman created an issue. See original summary.

iuana’s picture

StatusFileSize
new3.77 KB

I added the verification of hasDefinition on the entity type id.

iuana’s picture

Status: Active » Needs review
bojanz’s picture

Status: Needs review » Needs work

It impacts readability to indent the whole large block of code for what is an IF check for an edge case.

Instead, let's perform the IF check, and then continue; if the definition is missing. Basically having it function as a guard clause:

      if (!$this->entityManager->hasDefinition($entity_type_id)) {
        continue;
      }
iuana’s picture

StatusFileSize
new715 bytes

Yes, indeed. I reupload the patch. Thanks for reviewing it.

iuana’s picture

Status: Needs work » Needs review
iuana’s picture

StatusFileSize
new715 bytes

sorry for the name of the patch.

bojanz’s picture

Status: Needs review » Fixed

Thanks!

  • bojanz committed 56c2af5 on 8.x-2.x authored by iuana
    Issue #3086820 by iuana, mglaman, bojanz: Order item Views module...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.