Error when entities without the mapped data field appear in view.

Created on 13 December 2023, about 1 year ago

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;
    }

πŸ› Bug report
Status

Fixed

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bburg Washington D.C.

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024