Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#7 | commerce_hasDefinition_3086820_7.patch | 715 bytes | iuana |
|
Comments
Comment #2
iuana CreditAttribution: iuana at Softescu commentedI added the verification of hasDefinition on the entity type id.
Comment #3
iuana CreditAttribution: iuana at Softescu commentedComment #4
bojanz CreditAttribution: bojanz at Centarro commentedIt 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:
Comment #5
iuana CreditAttribution: iuana at Softescu commentedYes, indeed. I reupload the patch. Thanks for reviewing it.
Comment #6
iuana CreditAttribution: iuana at Softescu commentedComment #7
iuana CreditAttribution: iuana at Softescu commentedsorry for the name of the patch.
Comment #8
bojanz CreditAttribution: bojanz at Centarro commentedThanks!