paul121 / farm_rei

Adds restricted-entry interval (REI) fields to Input Logs and Materials.
1 stars 0 forks source link

EntityMetadataWrapperException: Unknown data property field_farm_area. #1

Closed mstenta closed 4 years ago

mstenta commented 4 years ago

Encountered an error screen when trying to view a Seeding log with this module installed. The error in the logs was:

EntityMetadataWrapperException: Unknown data property field_farm_area. in EntityStructureWrapper->getPropertyInfo() (line 354 of /var/www/html/profiles/farm/modules/contrib/entity/includes/entity.wrapper.inc).

I traced this to the farm_rei_entity_view_alter() function, which is looking for $log_wrapper->field_farm_area whenever a log page is displayed. Some logs do not have this field (namely Seeding logs and Transplanting logs).

I was able to temporarily fix it (at least enough to be able to view the seeding logs again) by adding a check:

    // If the log doesn't have an area reference field, bail.
    if (empty($log_wrapper->field_farm_area)) {
      return;
    }

I think the correct solution will be to look for Movement fields on logs (in addition to the field_farm_area field), because that is where Seedings/Transplantings (but also others) record the area reference.

Worth noting: I also found another place where the code is assuming $log_wrapper->field_farm_area exists: in farm_rei_build_area_message() - I'm not sure if this was causing any issues too, but should also be fixed.

paul121 commented 4 years ago

Good catch @mstenta! I've added a check to see if field_farm_area exists when checking a log: 0c9b3f843f11b70a294d7e8d217ee0016a06e312

Worth noting: I also found another place where the code is assuming $log_wrapper->field_farm_area exists: in farm_rei_build_area_message() - I'm not sure if this was causing any issues too, but should also be fixed.

I've included the check here as well. I don't think this would have caused any errors because that bit of code is only reached if the log defines an "active" REI. The only logs that can define an REI are logs that reference farm_materials, and currently Input logs are the only ones with this field. Input logs have field_farm_area so that "unknown data property" shouldn't happen - but I've included the check regardless, for future sake I suppose.

I also added a check for the log's movement field: c3b57ed355683bf94b420e91ae5bd8121b76e22b. This is so simple because any areas the movement references are passed on to later logic that checks for parent & sibling areas, active REI, etc.

mstenta commented 4 years ago

Perfect thanks @paul121 !