If OpenAI is unconfigured error in CKEditor plugin

Created on 19 December 2023, about 1 year ago
Updated 11 January 2024, 12 months ago

Problem/Motivation

If you enable openai and openai_ckeditor, and add the OpenAI plugin to CKEditor before configuring the API key for OpenAI, you will encounter an error.

Steps to reproduce

  1. Enable the openai and openai_ckeditor modules
  2. Add the OpenAI CKEditor plugin to the toolbar and save the text format
  3. Access the text format again, now you get an error stating that authorization is missing

Proposed resolution

Update the CKEditor plugin to check that the API Key exists. Add either a check like this in the top of
public function buildConfigurationForm(array $form, FormStateInterface $form_state) method.

    $config = \Drupal::configFactory()->getEditable('openai.settings');
    if (!$config->get('api_key')) {
      $form['completion'] = [
        '#markup' => '<p>' . $this->t('Please configure OpenAI API Settings first <a href="/admin/config/openai/settings">here</a>.') . '</p>',
      ];

      return $form;
    }

Alternatively, consider adding a dedicated function to the OpenAIApi service, such as function isConfigured(). So we can can call $this->api->isConfigured(), that can serve as a convenient check to ensure that the API is properly configured before making calls, providing a streamlined way to validate the configuration status before initiating operations, such as listing models or displaying the CKEditor settings form.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

OpenAI CKEditor

Created by

πŸ‡ΈπŸ‡ͺSweden Heggan

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024