- 🇺🇸United States danflanagan8 St. Louis, US
Comment #7 appears to be exactly correct.
The "Add to calendar" field type works in Layout Builder.
However, using the "Add to calendar" checkbox when configuring the display of a Date or Daterange field does not work in Layout Builder.
The bug is that in
_addtocalendar_preprocess_field()
, the code tries to get settings from the EntityViewDisplay, ignoring whether Layout Builder is in use:$entity = $variables['element']['#object']; $view_mode = $variables['element']['#view_mode']; $field_name = $variables['element']['#field_name']; // Determine if the field is multivalued. $multivalued = count($variables['items']) > 1; // Get the field formatter settings... $entity_display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode); $field_display = $entity_display->getComponent($field_name);
So that actually points to a workaround. The
$view_mode
in the code above evaluates to_custom
when the field is rendering in Layout Builder. That's not a view mode you can configure through field UI. That means the code will end up getting the field formatter configuration for thedefault
view mode.If you configure the default view mode for a Date field with the "Add to calendar" checkbox (though Field UI), then the "Add to calendar" button will show up when that Date field is displayed in Layout Builder.
- 🇺🇸United States danflanagan8 St. Louis, US
I found a very similar issue for another module that uses third_party_settings to enhance field formatters. #3099580: Doesn't work in layout builder →
The fix there would almost work for us. Unfortunately, we get a first-party setting from the field formatter as well:
$timeZone = (!empty($field_display['settings']['timezone_override'])) ? $field_display['settings']['timezone_override'] : date_default_timezone_get();
I don't see how to get that from
$variables
directly.