Error accessing Brandfolder settings after deleting Guest API key

Created on 4 October 2024, about 1 month ago

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();
    }
πŸ› Bug report
Status

Active

Version

5.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States wesleymusgrove

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @wesleymusgrove
    • ndewhurst β†’ committed 186639e2 on 5.0.x
      Issue #3478827 by wesleymusgrove, ndewhurst: clarify required API keys...
  • πŸ‡ΊπŸ‡ΈUnited States ndewhurst USA

    Hi Wesley - yes, the guest key was effectively required but not required on the config form. I just pushed an update making all three keys required and also restructuring the rest of the config form code to avoid that type of error if the BF API object is bad for whatever reason.
    Also, I believe these issues have already been addressed on the 6.x branch, along with a move to delegated key management, so consider testing that and upgrading once we issue a supported release from it.

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

Production build 0.71.5 2024