CRM_Core_Resources::addBundle() - Fix handling of array inputs
authorTim Otten <totten@civicrm.org>
Fri, 18 Sep 2020 00:26:38 +0000 (17:26 -0700)
committerTim Otten <totten@civicrm.org>
Fri, 18 Sep 2020 00:26:38 +0000 (17:26 -0700)
(This fixes a small bug in a new function added during this release -- part of #18247.)

The signature of `addBundle()` optionally accepts an array/iterable -- if
given, then it should add all the items from the array. For example:

```php
Civi::resources()->addBundle(['foo', 'bar']);
```

Before
------

It adds `foo` but then bails out on `bar`.

After
-----

It adds both `foo` and `bar`.

CRM/Core/Resources.php
CRM/Core/Resources/CollectionTrait.php

index 4a48798230c8ca38a716bd9c863eeb21dadb6bda..77467b61203eeba218c6dc50c47bb17eaaec6e1a 100644 (file)
@@ -206,8 +206,8 @@ class CRM_Core_Resources implements CRM_Core_Resources_CollectionAdderInterface
     if (is_iterable($bundle)) {
       foreach ($bundle as $b) {
         $this->addBundle($b);
-        return $this;
       }
+      return $this;
     }
 
     if (is_string($bundle)) {
index b7616edafce0776f5666a45368af04a8e74933b0..ec7ef1845356c3c4f95245ae17cfbfe9a65cf0f3 100644 (file)
@@ -327,8 +327,8 @@ trait CRM_Core_Resources_CollectionTrait {
     if (is_iterable($bundle)) {
       foreach ($bundle as $b) {
         $this->addBundle($b);
-        return $this;
       }
+      return $this;
     }
     if (is_string($bundle)) {
       $bundle = Civi::service('bundle.' . $bundle);