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?

Other EBT modules seem to be unaffected, it is only this module. I also checked all permissions and they look fine to me.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

shane birley created an issue. See original summary.

shane birley’s picture

Issue summary: View changes
shane birley’s picture

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...
levmyshkin’s picture

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

levmyshkin’s picture

Status: Active » Fixed
levmyshkin’s picture

Status: Fixed » Closed (fixed)

shane birley changed the visibility of the branch 3521289-block-does-not to hidden.