Fix type error in TaxonomyEntityIndexDepth: abs() expects int|float, string given

Created on 20 September 2024, 3 months ago

Problem/Motivation

When using the "TaxonomyEntityIndexDepth" filter in a view, an error occurs when a string is passed to the abs() function. The error message that appears is:

TypeError: abs(): Argument #1 ($num) must be of type int|float, string given in abs()

This happens because $this->options['depth'] is stored as a string, but the abs() function expects an integer or float. This mismatch causes the error and prevents the view from rendering correctly.

Steps to reproduce

  1. Install and enable the Taxonomy Entity Index module (version 8.x-1.16 or earlier).
  2. Create a view that uses the TaxonomyEntityIndexDepth filter.
  3. Attempt to render the view.
  4. Observe the error in the logs or in the frontend:
  5. TypeError: abs(): Argument #1 ($num) must be of type int|float, string given in abs()

Proposed resolution

The depth value ($this->options['depth']) should be cast to an integer before it is passed to the abs() function. This ensures that abs() receives a valid numeric value (int or float) and resolves the type error.

$depth = abs((int) $this->options['depth']);
πŸ› Bug report
Status

Fixed

Version

1.17

Component

Code

Created by

πŸ‡¨πŸ‡·Costa Rica thony1199

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