Error: Call to undefined method `getImageStyles()` in `OpenAiTaxonomy->getModelsForForm()`

Created on 3 June 2024, 7 months ago
Updated 7 June 2024, 6 months ago

Description:

I encountered an error while trying to manage the fields for a content type in my Drupal site. The error indicates that the getImageStyles() method is undefined in the GeneralHelper class, which is called by the OpenAiTaxonomy class in the ai_interpolator_openai module.

Steps to Reproduce:

  1. Navigate to the content type management page: /admin/structure/types/manage/information/fields
  2. Attempt to manage a field: /admin/structure/types/manage/information/fields/node.information.field_topics
  3. Observe the error message displayed.

Error Message:

Error: Call to undefined method Drupal\ai_interpolator\Rulehelpers\GeneralHelper::getImageStyles() in Drupal\ai_interpolator_openai\Plugin\AiInterPolatorFieldRules\OpenAiTaxonomy->getModelsForForm() (line 75 of /home/nomadsland/web/modules/contrib/ai_interpolator_openai/src/OpenAiTrait.php).

Backtrace:

#0 /home/nomadsland/web/modules/contrib/ai_interpolator_openai/src/OpenAiTrait.php(26): Drupal\ai_interpolator_openai\Plugin\AiInterPolatorFieldRules\OpenAiTaxonomy->getModelsForForm()
#1 /home/nomadsland/web/modules/contrib/ai_interpolator_openai/src/Plugin/AiInterpolatorFieldRules/OpenAiTaxonomy.php(40): Drupal\ai_interpolator_openai\Plugin\AiInterPolatorFieldRules\OpenAiTaxonomy->loadExtraAdvancedFormFields()
#2 /home/nomadsland/web/modules/contrib/ai_interpolator/src/FormAlter/AiInterpolatorFieldConfig.php(367): Drupal\ai_interpolator_openai\Plugin\AiInterPolatorFieldRules\OpenAiTaxonomy->extraAdvancedFormFields()
#3 /home/nomadsland/web/modules/contrib/ai_interpolator/ai_interpolator.module(16): Drupal\ai_interpolator\FormAlter\AiInterpolatorFieldConfig->alterForm()
#4 /home/nomadsland/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(545): ai_interpolator_form_field_config_edit_form_alter()
#5 /home/nomadsland/web/core/lib/Drupal/Core/Form/FormBuilder.php(841): Drupal\Core\Extension\ModuleHandler->alter()
#6 /home/nomadsland/web/core/lib/Drupal/Core/Form/FormBuilder.php(284): Drupal\Core\Form\FormBuilder->prepareForm()
#7 /home/nomadsland/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm()
#8 [internal function]: Drupal\Core\Controller\FormController->getContentResult()
#9 /home/nomadsland/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#10 /home/nomadsland/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#11 /home/nomadsland/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
#12 /home/nomadsland/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#13 /home/nomadsland/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#14 /home/nomadsland/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#15 /home/nomadsland/web/modules/contrib/redirect_after_login/src/RedirectMiddleware.php(44): Symfony\Component\HttpKernel\HttpKernel->handle()
#16 /home/nomadsland/web/modules/contrib/simple_oauth/src/HttpMiddleware/BasicAuthSwap.php(68): Drupal\redirect_after_login\RedirectMiddleware->handle()
#17 /home/nomadsland/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle()
#18 /home/nomadsland/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#19 /home/nomadsland/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#20 /home/nomadsland/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle()
#21 /home/nomadsland/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle()
#22 /home/nomadsland/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#23 /home/nomadsland/vendor/asm89/stack-cors/src/Cors.php(53): Drupal\page_cache\StackMiddleware\PageCache->handle()
#24 /home/nomadsland/web/core/modules/ban/src/BanMiddleware.php(50): Asm89\Stack\Cors->handle()
#25 /home/nomadsland/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle()
#26 /home/nomadsland/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#27 /home/nomadsland/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#28 /home/nomadsland/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#29 /home/nomadsland/web/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#30 /home/nomadsland/web/index.php(19): Drupal\Core\DrupalKernel->handle()
#31 {main}

Additional Information:

The error occurs when the method getImageStyles() is called in OpenAiTaxonomy->getModelsForForm() method, but this method is not defined in the GeneralHelper class. Adding the following method to the GeneralHelper class resolves the issue:

namespace Drupal\ai_interpolator\Rulehelpers;

class GeneralHelper {
    // Other methods...

    /**
     * Returns an array of image styles.
     *
     * @return array
     *   An associative array of image styles.
     */
    public function getImageStyles() {
        $styles = [];
        // Logic to get image styles.
        // For example, you can use Drupal's image style service:
        $image_styles = \Drupal::entityTypeManager()->getStorage('image_style')->loadMultiple();
        foreach ($image_styles as $style) {
            $styles[$style->id()] = $style->label();
        }
        return $styles;
    }
}

Suggested Resolution:

Please add the getImageStyles() method to the GeneralHelper class to ensure that the OpenAiTaxonomy class can successfully call this method.

Thank you for your attention to this matter.

💬 Support request
Status

Active

Version

1.0

Component

Code

Created by

🇰🇬Kyrgyzstan dan_metille

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

Comments & Activities

Production build 0.71.5 2024