Layout Builder Display for anonymous users cannot use JS callback

Created on 26 October 2023, about 1 year ago
Updated 3 November 2023, about 1 year ago

Problem/Motivation

When viewing an office hours field as an anonymous user, the configured display settings are not being displayed. For example, if the 'Show only current day' option is selected in Layout Builder, all of the hours are being displayed to anonymous users.

Steps to reproduce

1) Configure an office hours field on a content type.
2) In Layout Builder, add the field to the display and select 'Show only current day' for 'Number of days to show'.
3) Create a new node and populate the office hours field.
4) SIgn out of the site and view the node - all hours are displayed rather than only the current day's hours.

Proposed resolution

This problem seems to be caused by office_hours_status_update.js. If I disable that script from running, the configured display is shown. When that script runs, it overwrites the display with the full list of hours (and also does not respect label hidden settings, etc).

Remaining tasks

I'm not sure what the permanent solution is for this because I don't really understand what that script is doing, but the cache clearing for anonymous users should take into account the display settings that are configured for the field.

🐛 Bug report
Status

Fixed

Version

1.12

Component

Code - formatter

Created by

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

Comments & Activities

  • Issue created by @flitt1
  • I've created a patch that removes the update status changes that were done to the default office hours formatter. With this change, the hours display is shown to anonymous users as expected (without the update script overwriting the display).

    If someone knows a way to keep the cache update stuff in there but also respect the display settings that would be better, I just don't know how to do that.

  • 🇳🇱Netherlands johnv

    The JS is added to circumvent the problems with field cache for anonymous users , when you have an open/close status displayed, or not all days per week, with page_cache enabled.

    I wonder, why a contrib field should worry about the layout builder peculiarities.
    There is now an exception in theming, according to the fix in 🐛 Layout Builder error with 'Exception Day' Fixed . The relevant code is now in office_hours.theme.inc .
    I guess it can/should be moved to some 'real' php code .

  • 🇳🇱Netherlands johnv

    Thanks for your report.
    The root cause is in core\modules\layout_builder\src\Entity\LayoutBuilderEntityViewDisplay.php::buildMultiple().

     public function buildMultiple(array $entities) {
        $build_list = parent::buildMultiple($entities);
    
        // Layout Builder can not be enabled for the '_custom' view mode that is
        // used for on-the-fly rendering of fields in isolation from the entity.
        if ($this->isCustomMode()) {
          return $build_list;
        }
    // ...
    }
    

    And this is exactly what happens. The field is rendered again, in isolation.

    • johnv committed a29abb6a on 8.x-1.x
      Issue #3397009 by flitt1: Layout Builder Display for anonymous users...
  • Status changed to Fixed about 1 year ago
  • 🇳🇱Netherlands johnv

    Thanks for the report. Committed a smarter fix.

    Apparently you have a cache-dependent display. (using exceptions, or open/closed/current/next formatter).

    Please test the following:
    - edit an entity. Make sure the entity opens/closes in a few minutes.
    - as an anonymous user, display the entity. Check the open/close indicator
    - before the open/close indicator, refresh the page some times (use CTRL-F5 once to refresh JS file, further F5)
    - wait until the opening/closing time has passed, and refresh the page (F5), check the open/closed indicator

    Each time, the data can be fetched from cache or created new. In your case, the 'read from cache and update field with JS' is now disabled.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024