From 8f60f7fbd08d4fa9f7fef4e96b602f8d344eaa4a Mon Sep 17 00:00:00 2001 From: Peter Lindstrom Date: Wed, 17 Apr 2019 17:43:07 -0400 Subject: [PATCH] initialize $bundles for perms call --- reserve.inc | 12 ++++++++---- src/Controller/ReservePermissions.php | 15 ++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/reserve.inc b/reserve.inc index f3e2145..4fc9059 100644 --- a/reserve.inc +++ b/reserve.inc @@ -1031,6 +1031,7 @@ function reserve_yyyymmdd($month, $day) { * */ function reserve_get_reserve_bundles() { + $bundles = array(); $fieldmap = \Drupal::entityManager()->getFieldMap(); foreach ($fieldmap as $entity_type => $typedef) { foreach ($typedef as $field) { @@ -1079,12 +1080,15 @@ function ebundle_split($ebundle, $part) { * e.g.: Room (node) */ function ebundles_formatted() { + $result = array(); $info = \Drupal::service("entity_type.bundle.info")->getAllBundleInfo(); $ebundles = reserve_get_reserve_bundles(); - foreach ($ebundles as $ebundle) { - $type = ebundle_split($ebundle, 'type'); - $bundle = ebundle_split($ebundle, 'bundle'); - $result[$ebundle] = $info[$type][$bundle]['label'] . " ($type)"; + if (count($ebundles)) { + foreach ($ebundles as $ebundle) { + $type = ebundle_split($ebundle, 'type'); + $bundle = ebundle_split($ebundle, 'bundle'); + $result[$ebundle] = $info[$type][$bundle]['label'] . " ($type)"; + } } return $result; } diff --git a/src/Controller/ReservePermissions.php b/src/Controller/ReservePermissions.php index d5e7e93..5a23065 100644 --- a/src/Controller/ReservePermissions.php +++ b/src/Controller/ReservePermissions.php @@ -46,13 +46,14 @@ class ReservePermissions implements ContainerInjectionInterface { $permissions = []; $ebundles = ebundles_formatted(); - - foreach ($ebundles as $ebundle => $bundle) { - $permissions += [ - 'access calendar for ' . $ebundle => [ - 'title' => $this->t('Allow access to the calendar for ' . $bundle), - ] - ]; + if (count($ebundles)) { + foreach ($ebundles as $ebundle => $bundle) { + $permissions += [ + 'access calendar for ' . $ebundle => [ + 'title' => $this->t('Allow access to the calendar for ' . $bundle), + ] + ]; + } } return $permissions;