When I try as an admin to update reservation availability in an event I get the following error in my logs and the hours/dates are not updated:

<blockquote>Warning: Invalid argument supplied for foreach() in Drupal\bee\Form\UpdateAvailabilityForm->createHoulyEvent() (line 305 of /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/modules/bee/src/Form/UpdateAvailabilityForm.php) #0 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/includes/bootstrap.inc(584): _drupal_error_handler_real(2, 'Invalid argumen...', '/var/www/vhosts...', 305, Array) #1 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/modules/bee/src/Form/UpdateAvailabilityForm.php(305): _drupal_error_handler(2, 'Invalid argumen...', '/var/www/vhosts...', 305, Array) #2 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/modules/bee/src/Form/UpdateAvailabilityForm.php(215): Drupal\bee\Form\UpdateAvailabilityForm->createHoulyEvent(Object(DateTime), Object(DateTime), '5', 'available') #3 [internal function]: Drupal\bee\Form\UpdateAvailabilityForm->submitForm(Array, Object(Drupal\Core\Form\FormState)) #4 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/Form/FormSubmitter.php(111): call_user_func_array(Array, Array) #5 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/Form/FormSubmitter.php(51): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState)) #6 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/Form/FormBuilder.php(589): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState)) #7 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/Form/FormBuilder.php(318): Drupal\Core\Form\FormBuilder->processForm('bee_update_avai...', Array, Object(Drupal\Core\Form\FormState)) #8 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/Form/FormBuilder.php(216): Drupal\Core\Form\FormBuilder->buildForm('bee_update_avai...', Object(Drupal\Core\Form\FormState)) #9 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/modules/bee/src/Controller/BeeController.php(120): Drupal\Core\Form\FormBuilder->getForm('Drupal\\bee\\Form...', Object(Drupal\node\Entity\Node)) #10 [internal function]: Drupal\bee\Controller\BeeController->availability(Object(Drupal\node\Entity\Node)) #11 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #12 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #13 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #14 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #15 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #16 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #17 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/modules/bat_api/src/StackMiddleware/BatApiMiddleware.php(44): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #18 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Drupal\bat_api\StackMiddleware\BatApiMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #19 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #20 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #21 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #22 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/modules/services/src/StackMiddleware/FormatSetter.php(44): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #23 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\services\StackMiddleware\FormatSetter->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #24 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #25 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #26 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/DrupalKernel.php(669): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #27 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #28 {main}.</blockquote>

How can I fix this?
Thanks in advance

Comments

m_dimitris created an issue. See original summary.

acrollet’s picture

Hi there, thanks for the report - can you give the exact BEE configuration and steps you are following to produce this error?

m_dimitris’s picture

Hello again and thanks for ur help,

I have an "exhibition" content type where BEE is enabled as follows:

  1. Make this entity type bookable
  2. Flexible Bookings (allows bookings of any length)
  3. Generally available (Use for resources that are usually available unless there is a booking. Examples are meeting rooms and equipment)

This error appears when I try to update the availability in the "Availability" tab in content edit form. I try to change the start and end dates or the state and the page just reloads with an empty calendar.

Also I dont know wether it is related but when I tried to unset the bee from the content type the following message appeared in logs (the second time I tried it worked correctly) :

Error: Call to a member function delete() on null in bee_node_type_edit_form_submit() (line 397 of /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/modules/bee/bee.module) #0 [internal function]: bee_node_type_edit_form_submit(Array, Object(Drupal\Core\Form\FormState)) #1 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/Form/FormSubmitter.php(111): call_user_func_array('bee_node_type_e...', Array) #2 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/Form/FormSubmitter.php(51): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState)) #3 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/Form/FormBuilder.php(589): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState)) #4 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/Form/FormBuilder.php(318): Drupal\Core\Form\FormBuilder->processForm('node_type_edit_...', Array, Object(Drupal\Core\Form\FormState)) #5 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/Controller/FormController.php(93): Drupal\Core\Form\FormBuilder->buildForm('node_type_edit_...', Object(Drupal\Core\Form\FormState)) #6 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch)) #7 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #8 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #9 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #10 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #11 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() #12 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #13 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/modules/bat_api/src/StackMiddleware/BatApiMiddleware.php(44): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #14 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Drupal\bat_api\StackMiddleware\BatApiMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #15 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #16 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #17 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #18 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/modules/services/src/StackMiddleware/FormatSetter.php(44): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #19 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\services\StackMiddleware\FormatSetter->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #20 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #21 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #22 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/core/lib/Drupal/Core/DrupalKernel.php(669): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #23 /var/www/vhosts/dimarkopoulos.eu/vouli.dimarkopoulos.eu/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #24 {main}.

acrollet’s picture

Status: Active » Postponed (maintainer needs more info)

Hi there,

I'm unable to reproduce with the settings you mention, can you post exact steps to reproduce the issue on simplytest.me ? Please note that the calendar defaults to the current date, if you've changed availability for a different date you'll need to scroll the calendar to that date.

carnerik’s picture

I'm getting the same error. Here are the steps on simplytest.me:

  • Install BAT (8.x-1.0-rc3) and BEE (8.x-1.0-beta6) + dependencies + submodules
  • Create a new content type and enable bookings with the flexible bookings, periodically available settings. All other settings are default.
  • Create a test node of the new content type.
  • Using the Availability tab of the test node, add an available hour to the unit. (I tried it with the default current date and with changing the date to the next day, or with different hours. It doesn't seem to make a difference.)
  • On clicking the update button, the event is created, but with the "Invalid argument supplied for foreach()" error.

This was using Drupal 8.6.7. I tried to test it again today with 8.6.9, but I couldn't because of an in issue installing BAT. I also had these modules installed: Commerce 8.x-2.11 + dependencies + submodules (all but Promotion, Payment Example, and Tax); Webform 8.x-5.1 + Webform Node, UI, and Submission Log submodules; and Commerce Web Order 8.x-1.x-dev.

xaver’s picture

Hi,

I've installed the bee module "^1.0@beta" on drupal 8.6.10 and created a simple content type: booking lenght: daily booking + generally available. Unfortunately when I tray to update the availability a receive the following warning:

Warning: Invalid argument supplied for foreach() in Drupal\bee\Form\UpdateAvailabilityForm->createDailyEvent() (line 259 of modules/contrib/bee/src/Form/UpdateAvailabilityForm.php).

Drupal\bee\Form\UpdateAvailabilityForm->createDailyEvent(Object, Object, '2', 'unavailable') (Line: 187)
Drupal\bee\Form\UpdateAvailabilityForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 589)
Drupal\Core\Form\FormBuilder->processForm('bee_update_availability_form', Array, Object) (Line: 318)
Drupal\Core\Form\FormBuilder->buildForm('bee_update_availability_form', Object) (Line: 216)
Drupal\Core\Form\FormBuilder->getForm('Drupal\bee\Form\UpdateAvailabilityForm', Object) (Line: 120)
Drupal\bee\Controller\BeeController->availability(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 44)
Drupal\bat_api\StackMiddleware\BatApiMiddleware->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 44)
Drupal\services\StackMiddleware\FormatSetter->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

fietserwin’s picture

Status: Postponed (maintainer needs more info) » Active

Same here.
- form: node/{node}/availability
- Open "Update availability"
- select dates
- click on "Update Availability": Warning: Invalid argument supplied for foreach() in…

Looking at the code it is quite simple what happens:

$booked_units = bat_event_get_matching_units(...);
...
foreach ($booked_units as $unit) { // offending line
  ...
}
...

- bat_event_get_matching_units() returns array|bool. We get a warning, so apparently indeed a bool has been returned.
- when will a bool be returned: when bat_event_get_matching_units_from_calendar() does not find any matching unit, that is, there are no matching units that have a booking during the period we want to update the availability for.
- solution: insert a check on $booked_units before executing the foreach

However:
Returning false for an empty list/set is considered contra-productive (QED in this issue), so IMO, this issue should be moved to the bat project issue queue to have bat_event_get_matching_units_from_calendar() return an empty array and updating phpdoc for that function and the calling function bat_event_get_matching_units().

acrollet’s picture

Project: BEE Bookable Entities Everywhere » BAT Booking and Availability Management Tools for Drupal
Status: Active » Fixed

@fietserwin thanks for the research and suggestion, I've made the change in BAT.

  • acrollet committed 0299c78 on 8.x-1.x
    Issue #3020832: Warning on updating reservation availabilty
    

Status: Fixed » Closed (fixed)

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