The getColSize() calculates the number of columns a grid will take given the size of a specific column.

  • col-md-4 will take 3 columns as 12/4 = 3
  • col-lg-12 will take 1 column as 12/12 = 1

But, extra small columns are in the form of col-4 and not col-xs-4. This means that the preg_match() call with the regular expression ~col-[a-z]{2}-([0-9]*)~ will always fail and return FALSE for extra small columns.

By adding an additional call to preg_match() with the regular expression ~col-([0-9]*)~ catches this scenario.

diff --git a/web/modules/contrib/views_bootstrap/src/ViewsBootstrap.php b/web/modules/contrib/views_bootstrap/src/ViewsBootstrap.php
index 4823816b..879ea23f 100644
--- a/web/modules/contrib/views_bootstrap/src/ViewsBootstrap.php
+++ b/web/modules/contrib/views_bootstrap/src/ViewsBootstrap.php
@@ -104,6 +104,9 @@ public static function getColSize($size) {
     if (preg_match('~col-[a-z]{2}-([0-9]*)~', $size, $matches)) {
       return 12 / $matches[1];
     }
+    if (preg_match('~col-([0-9]*)~', $size, $matches)) {
+      return 12 / $matches[1];
+    }

     return FALSE;
   }
CommentFileSizeAuthor
#5 3071152-5-division_by_zero_error.patch427 bytesglynster

Comments

paddy_deburca created an issue. See original summary.

RabiaSajjad’s picture

Same error, applied change and works now.

Salez-Poivrez’s picture

Same problem. Call to preg_match() added. It's works fine for me.

drupgirl’s picture

+1 RTBC manually patched and it worked. Thank you!

glynster’s picture

StatusFileSize
new427 bytes

Same issue exists in version 8.x-3.5. I have back ported a patch and this resolves the issue as well. All credits to @paddy_deburca we use composer so we need patches :)

shelane’s picture

Version: 8.x-4.1 » 5.4.x-dev
komlenic’s picture

Status: Active » Reviewed & tested by the community

Confirming that the issue exists in 5.3.0 and that the patch in #5 fixes the issue in 8.x-3.5/5.3.0.

Does this need to be applied to the 5.3 and 5.4 branches?

chris matthews’s picture

I'm running into this issue on 5.3.0 (for Bootstrap 3). Any chance the patch in #5 can be committed to -dev?

shelane’s picture

I'm not sure how this would work for Bootstrap 3 as the columns are all in the form of col-sm-1, col-md-1, etc.

chris matthews’s picture

Drupal: 9.4.7
PHP: 8.1
Bootstrap: 8.x-3.25
Views Bootstrap: 5.3.0

Before applying the patch in #5, below was the php error I was getting. After applying the patch the error was resolved.

Message DivisionByZeroError: Modulo by zero in __TwigTemplate_5a297159902bd77452b3a32b195c7d9a->doDisplay() (line 117 of /tmp/rolling/live_418/twig/633b314f71e36_views-bootstrap-grid.html_gqQPANHLUWgn4Erd9IyZPPw_t/9JC_yaiygW3Zy9cotXsAi59lgI0UE5VlacmZZBmy4gQ.php)

shelane’s picture

Can you share a screen shot of your settings that would enable me to recreate the error message?

chris matthews’s picture

@shelane Would it be possible for the patch in #5 to be committed? I've been using on the 3.x branch for quite a while with no issues.

noonoos’s picture

Just did upgrade. " - Upgrading drupal/views_bootstrap (5.5.0-beta2 => 5.5.0-beta3): Extracting archive"
and I am now getting this error on one page (Home Page)

shelane’s picture

If you are seeing this error after update to 5.5.0-beta, see related issue #3447965: 5.5.0-beta1 DivisionByZeroError: Modulo by zero and comments.

noonoos’s picture

Just did upgrade. " - Upgrading drupal/views_bootstrap (5.5.0-beta2 => 5.5.0-beta3): Extracting archive"
and I am now getting this error on one page (Home Page)

Issue resulted from the updated ViewsBootstrapCards.php plugin requiring extra data input than previous plugin causing the above error response.

  • shelane committed 80d06104 on 8.x-4.x
    Issue #3071152 by glynster, shelane, paddy_deburca: DivisionByZeroError...

  • shelane committed fc8f556f on 5.4.x
    Issue #3071152 by glynster, shelane, paddy_deburca: DivisionByZeroError...

  • shelane committed e069cc2e on 5.5.x
    Issue #3071152 by glynster, shelane, paddy_deburca: DivisionByZeroError...

  • shelane committed 2a6a6a72 on 5.3.x
    Issue #3071152 by glynster, shelane, paddy_deburca: DivisionByZeroError...

  • shelane committed 0e32c300 on 8.x-3.x
    Issue #3071152 by glynster, shelane, paddy_deburca: DivisionByZeroError...
shelane’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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