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.

Comments

shree.yesare created an issue. See original summary.

shree.yesare’s picture

Title: Add to calendar link is not visible on layout builder. » Add to calendar link is not visible on page build with layout builder.
pradeepjha’s picture

Assigned: Unassigned » pradeepjha
pradeepjha’s picture

StatusFileSize
new46.04 KB

Hi,
I'm not able to reproduce error. Even page build with layout builder, add to calendar button is showing. Please check this module with Drupal version.
Or let me know steps to reproduce error, then I can help you out.
Steps which I've followed:

  • Go to any content types display settings. Lets say Article.
  • Under Layout option choose `Use Layout builder`
  • Then add new section under layout
  • Assign `Add to calendar` block new section
  • Create article content and check Show add to calendar.
  • Now it will be visible on page.

Please find attached screenshot.

sharma.amitt16’s picture

Status: Active » Needs review
pradeepjha’s picture

Assigned: pradeepjha » Unassigned
matija5’s picture

StatusFileSize
new70.66 KB

Hi, I think I did reproduce this. 1st scenario is what pradeepjha said and it works. If you add AddToCalendar as a field then button is displayed.

But if you take Date field and check AddToCalendar when adding block of this field in Layout Builder then button is not displayed. Please see screenshot.

Regards.

matija5’s picture

Status: Needs review » Active
gg24’s picture

Status: Active » Closed (cannot reproduce)

I'm not able to reproduce the issue. I tried both scenarios suggested by @pradeepjha and @vebrovski but I am able to see properly the Add to Calendar Widget using Layout builder. Please feel free to reopen if in case you still face the issue.

pameeela’s picture

Status: Closed (cannot reproduce) » Active

I'm currently struggling with this issue. Using layout builder, checking the box to enable this on a date field does not seem to do anything. If I revert back to not using LB it works as expected.

And I do not appear to have the option to add 'Add to calendar' as a separate block, as some here have suggested. Don't know what I am missing.

Using Drupal 9.0.7 with 8.x-3.2

pameeela’s picture

I figured out how to get the block, by adding an 'Add to calendar' field to the node type, but it still doesn't display anything using LB.

danflanagan8’s picture

Version: 8.x-3.1 » 8.x-3.x-dev

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.

danflanagan8’s picture

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.