- Issue created by @bburg
- Issue was unassigned.
- Status changed to Fixed
about 1 year ago 3:52pm 13 December 2023 Automatically closed - issue fixed for 2 weeks with no activity.
If an entity without the the mapped date field appears in the ical view, an error will be encountered in addDateRangeEvent. Example:
The website encountered an unexpected error. Please try again later.
InvalidArgumentException: Field field_daterange is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 583 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).
Drupal\Core\Entity\ContentEntityBase->get('field_daterange') (Line: 372)
Drupal\views_ical\Plugin\views\row\IcalFieldsWizard->addDateRangeEvent(Array, Object, Object, Array) (Line: 110)
This will vary depending on your field name, but it's trying to access a field named "field_daterange" on an entity where that field does not exist.
Solution:
WE should check that the field exists before trying to access it.
Something like
if (!$entity->hasField($field_mapping['date_field'])) {
// The view has been misconfigured with a field that does not exist on the entity.
\Drupal::messenger()->addError(t('Field does not exist on entity for use in calendar. Please ensure that only entities with the correctly mapped date field appear in the iCal view.'));
return;
}
Fixed
Code
Automatically closed - issue fixed for 2 weeks with no activity.