FWA plugin error: Call to a member function get() on array

Created on 30 July 2025, 6 days ago

Problem/Motivation

The ListInteger and Boolean fwa plugins are broken. I’m assuming others e.g. ListFloat are also broken. Something has changed in 1.2.x-dev around July 21st, maybe AutomatorBaseAction?

Sample error looks like this:

Error: Call to a member function get() on array in Drupal\ai_automators\Plugin\FieldWidgetAction\Boolean->saveFormValues() (line 49 of /var/www/html/web/modules/contrib/ai/modules/ai_automators/src/Plugin/FieldWidgetAction/Boolean.php)

Steps to reproduce (required for bugs, but not feature requests)

- Enable AI Automator on a boolean field;
- Choose AI Automator Type » LLM Boolean;
- Configure AI Automator Settings;
- Go to e.g. admin/structure/types/manage/page/form-display
- Configure FWA on boolean field
- Edit a Page node and click on the fwa button

🐛 Bug report
Status

Active

Version

1.2

Component

Field Widget Actions

Created by

🇨🇦Canada bisonbleu

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

Merge Requests

Comments & Activities

  • Issue created by @bisonbleu
  • Pipeline finished with Success
    4 days ago
    Total: 202s
    #562491
  • 🇨🇦Canada bisonbleu

    Thanks for this fix @anjaliprasannan. That said, your fix is at the plugin level, not upstream which is where, I think @Marcus_Johansson was alluding to when he wrote «I know where this comes from» in Slack. The issue description also mentions that this affects other plugins e.g. ListFloat, etc.

    Perhaps @Marcus_Johansson can provide more details about what he meant by «I know where this comes from»…?

  • 🇮🇳India anjaliprasannan

    @bisonbleu

    I am trying to improve the saveFormValues() in AutomatorBaseAction like,

    protected function saveFormValues(array &$form, string $form_key, $entity, ?int $key = NULL): array {
    
        if (is_null($key)) {
          // If not key is provided, we should iterate through all items.
          foreach ($entity->get($form_key) as $index => $item) {
            $value = NULL;
            if (is_array($item)) {
              if (isset($item[$this->formElementProperty])) {
                $value = $item[$this->formElementProperty];
              }
            }
            elseif (is_object($item) && method_exists($item, 'get')) {
              if ($item->get($this->formElementProperty)) {
                $value = $item->get($this->formElementProperty)->getValue();
              }
            }
            if ($value !== NULL) {
              $form[$form_key]['widget'][$index][$this->formElementProperty]['#value'] = $value;
            }
          }
        }
        else {
          if (isset($entity->get($form_key)[$key])) {
            $item = NULL;
            foreach ($entity->get($form_key) as $index => $item) {
              if ($index === $key) {
                break;
              }
            }
            $value = NULL;
            if (is_array($item)) {
              if (isset($item[$this->formElementProperty])) {
                $value = $item[$this->formElementProperty];
              }
            }
            elseif (is_object($item) && method_exists($item, 'get')) {
              if ($item->get($this->formElementProperty)) {
                $value = $item->get($this->formElementProperty)->getValue();
              }
            }
            if ($value !== NULL) {
              $form[$form_key]['widget'][$key][$this->formElementProperty]['#value'] = $value;
            }
          }
        }
    
        return $form[$form_key];
      }
    
    

    the method now correctly handles both array and object field items. This means that most plugin-level overrides of saveFormValues() are no longer necessary unless they add widget-specific logic.

    I recommend removing the redundant saveFormValues() methods from individual FieldWidgetAction plugins and letting them inherit the base implementation. If that is allowed I can move further.

    Thanks

Production build 0.71.5 2024