Warning: Undefined array key "back_to_top_speed" in back_to_top_page_attachments()

Created on 15 December 2024, 7 days ago

Problem/Motivation

When using the Back To Top module, the following warning appears:
Warning: Undefined array key "back_to_top_speed" in back_to_top_page_attachments() (line 35 of modules/contrib/back_to_top/back_to_top.module).

The warning occurs when the back_to_top_speed value is not set in the module's settings.

Steps to reproduce

  1. Install and enable the "Back To Top" module.
  2. Leave the "back_to_top_speed" configuration empty or unset.
  3. Load any page where the module is active.
  4. Check the logs or observe the warning on the page.

Proposed resolution

To prevent the warning, the value of back_to_top_speed should be checked before assigning it.

Replace:

$attachments['#attached']['drupalSettings']['back_to_top']['back_to_top_speed'] = $settings['back_to_top_speed'];
With:
$attachments['#attached']['drupalSettings']['back_to_top']['back_to_top_speed'] = isset($settings['back_to_top_speed']) ? $settings['back_to_top_speed'] : 1000;

This ensures that a default value (1000) is used if back_to_top_speed is not set.

Remaining tasks

Apply the proposed fix to the codebase.
Test the module after the fix to confirm that the warning no longer appears.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇪🇸Spain whereiam

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024