Roomify / bat_drupal

Booking and Availability Management Tools for Drupal 7 and Drupal 8
33 stars 7 forks source link

BAT Calendar Reference will not enable #10

Closed simmonspaul closed 8 years ago

simmonspaul commented 8 years ago

My environment was setup with bat (1.0.0-alpha), bat_drupal (7.x-1.x-dev downloaded 20 minutes ago via zip file) and bat_api (7.x-2.0).

BAT Calendar Reference can not be enabled. All other BAT components enable without issue.

Fatal error: Can't use function return value in write context in /home2/scoundre/git/pstaging/sites/all/modules/bat/modules/bat_calendar_reference/bat_calendar_reference.module on line 364

lines 364-6 are if (!empty(array_filter($field['settings']['referenceable_unit_types']))) { $query->condition('u.type_id', array_filter($field['settings']['referenceable_unit_types']), 'IN'); }

if commented out and proceed, same error as above complaining about line 467

lines 467-469 are if (!empty(array_filter($field['settings']['referenceable_event_types']))) { $query->condition('u.id', array_filter($field['settings']['referenceable_event_types']), 'IN'); }

if commented out and proceed, same error as above complaining about line 564

lines 564-566 are if (!empty(array_filter($field['settings']['referenceable_event_types']))) { $query->condition('u.type_id', array_filter($field['settings']['referenceable_event_types']), 'IN'); }

Once these lines are all commented out, the BAT Calendar Reference module can be enabled.

simmonspaul commented 8 years ago

Ok, here is what I think is the cause of this issue.

I am not a coder by any means, but I can hack and google search... please do what you will with the following observation.

As per http://stackoverflow.com/questions/1532693/weird-php-error-cant-use-function-return-value-in-write-context... empty is not a function but a language construct and it only takes variables. Having said that since PHP 5.5 is supports more than variables.

I am on PHP 5.4.45 as constrained by my host provider... so I am snookered with the capabilities of empty.

A hack to get around this issue (that was better than commenting the lines out) was to do it in two steps.

original code if (!empty(array_filter($field['settings']['referenceable_unit_types']))) { $query->condition('u.type_id', array_filter($field['settings']['referenceable_unit_types']), 'IN'); }

hack $holder1 = array_filter($field['settings']['referenceable_unit_types']);

if (!empty($holder1)) {$query->condition('u.type_id', array_filter($field['settings']['referenceable_unit_types']), 'IN'); }

Making these replacements allowed the module to enable. Not sure how to test if the underlying functionality is working though.

simmonspaul commented 8 years ago

Thank you Nicolò. As per commit "Fixes for php < 5.5" this now is working for me. https://github.com/Roomify/bat_drupal/commit/ab3d2fbfea4ca1eecaff6a228fc7483a4c7f71ea Regards Paul