Block Does Not Render for Anonymous Users

Created on 26 April 2025, 21 days ago

Problem/Motivation

The blocks created by Countdown do not load for anonymous users.

Steps to reproduce

  • Enable module.
  • Edit Layout on page.
  • Add countdown block.
  • Save.

When logged in, block is visible.
When logged out, block does not render.

It might be a jQuery issue but I loaded the jQuery Once module which is supposed to help with jQuery issues but there was no change. It is possible it is a cache problem since the block shouldn't really be cached?

🐛 Bug report
Status

Active

Version

1.4

Component

Code

Created by

🇨🇦Canada Shane Birley

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

Merge Requests

Comments & Activities

  • Issue created by @Shane Birley
  • 🇨🇦Canada Shane Birley

    I went through everything to make sure I wasn't crazy, but I do think there are a couple of issues here. I ran through a few implementations of adding declarations in the theme and it works fine but the real issue is just an update of the module itself since it has particular requirements:

    1. The ebt_countdown is making a declaration for Drupal.behaviors and it isn't available in Drupal 11. So I added the declarations I made in the theme in the modules libraries.yml file.

    ebt_countdown:
      version: 1.x
      css:
        component:
          /libraries/flipdown/dist/flipdown.min.css: { minified: true }
          css/flipdown.css: {}
      js:
        /libraries/flipdown/dist/flipdown.min.js: { minified: true }
        js/ebt_countdown.js: {}
      dependencies:
        - core/jquery
        - core/once
        - core/drupal
        - core/drupalSettings
    
    new_year:
      css:
        component:
          css/new-year.css: {}

    I then took a quick peek at the ebt_countdown.js and added the declarations:

    (function ($, Drupal, drupalSettings) {
    
      /**
       * EBT Countdown behavior.
       */
      Drupal.behaviors.ebtCountDown = {
        attach: function (context, settings) {
          // Initialize once behavior.
          var countdowns = once('ebt-countdown-block', '.ebt-countdown-date', context);
    
          countdowns.forEach(function(countdown) {
            // Get block ID.
            var countdownWrapper = countdown.closest('.ebt-block-countdown');
            if (!countdownWrapper) {
              console.warn('EBT Countdown: Countdown wrapper not found.');
              return;
            }
    
            var countdownWrapperId = countdownWrapper.getAttribute('id');
            
            // Get block EBT settings.
            if (!drupalSettings['ebtCountdown'] || !drupalSettings['ebtCountdown'][countdownWrapperId]) {
              console.warn('EBT Countdown: Settings not found for ID: ' + countdownWrapperId);
              return;
            }
    
            var ebtOptions = drupalSettings['ebtCountdown'][countdownWrapperId];
    
            // Prepare options for javascript plugin.
            var countdownTimestamp = parseInt(countdown.getAttribute('data-date'), 10);
            if (isNaN(countdownTimestamp)) {
              console.warn('EBT Countdown: Invalid timestamp for countdown.');
              return;
            }
    
            var countdownId = countdown.getAttribute('id');
    
            // Init javascript plugin.
            if (typeof FlipDown === 'function') {
              try {
                new FlipDown(countdownTimestamp, countdownId, {
                  theme: ebtOptions['options']['color_theme'],
                  headings: [
                    ebtOptions['options']['heading_days'],
                    ebtOptions['options']['heading_hours'],
                    ebtOptions['options']['heading_minutes'],
                    ebtOptions['options']['heading_seconds'],
                  ],
                }).start();
              } catch (error) {
                console.error('EBT Countdown: Failed to initialize FlipDown.', error);
              }
            } else {
              console.warn('EBT Countdown: FlipDown library is missing or not loaded.');
            }
          });
        }
      };
    
    })(jQuery, Drupal, drupalSettings);

    Hopefully this helps.

    • levmyshkin committed 50904cf1 on 1.4.x
      Issue #3521289 by shane birley: Block Does Not Render for Anonymous...
  • 🇷🇸Serbia levmyshkin Novi Sad, Serbia

    Hi Shane Birley, thank you for your report and patch! I applied it and released 1.4.6 version for EBT Countdown.

  • 🇷🇸Serbia levmyshkin Novi Sad, Serbia
  • 🇷🇸Serbia levmyshkin Novi Sad, Serbia
Production build 0.71.5 2024