Problem/Motivation
I have a Brandfolder API Key for a Brandfolder CDN user that has the "Admin" role. On the Drupal Brandfolder settings page, my previous configuration only had an API key in the "Guest" field. I'm trying to update that to only provide the API Key in the "Admin" field.
Steps to reproduce
When I remove the API key from the "Guest" field and try to save the page, I get the following error:
The website encountered an unexpected error. Please try again later.
Error. Call to a member function enableVerboseLogging() on bool in Drupal brandfolder Form BrandfolderSettingsForm->buildForm() (line 69 of modules/contrib/brandfolder/src/Form/BrandfolderSettingsForm.php).
call_user_func_array (Array, Array) (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveform('brandfolder settings form', Object) (Line: 283)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Proposed resolution
I can see that this code `$bf->enableVerboseLogging();` in `brandfolder/src/Form/BrandfolderSettingsForm.php` doesn't adequately handle the possibility of `$bf` being `false`, which appears to be what is happening if the "Guest" API key is removed from the settings page and the page is saved.
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('brandfolder.settings');
$api_keys = [];
$messenger = $this->messenger();
$brandfolder_id = $config->get('brandfolder_id');
$bf = brandfolder_api();
if ($config->get('verbose_log_mode')) {
$bf->enableVerboseLogging();
}
Remaining tasks
I didn't see anything on the Brandfolder Drupal settings page that indicated that the Guest API key was a required field... or if all three types of API keys need to be provided even if I'm only given a single API key with the "Admin" Brandfolder role. Perhaps some help text or form validation should be added that enforces these rules?
I'm not sure if a patch needs to be submitted for this module or if a merge request should be created on its github repo... but I think checking to make sure `$bf` is _not_ false should do it.
if ($bf && $config->get('verbose_log_mode')) {
$bf->enableVerboseLogging();
}