Add to calendar link is not visible on page build with layout builder.

Created on 28 January 2020, almost 5 years ago
Updated 11 August 2023, over 1 year ago

Added a Date range date field on layout manager and enabled the "Add to calendar" check. No link is displayed on the content page.
Configure the date field in default view mode then the Add to calendar reflects on content page. The field actually, refers to the default mode settings on the layout builder.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇮🇳India shree.yesare

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸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 the default 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.

Production build 0.71.5 2024