- Issue created by @bisonbleu
- Merge request !814Issue #3538762: FWA plugin error: Call to a member function get() on array → (Open) created by Unnamed author
- 🇨🇦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