octobercms/october · error · ApplicationException

The model class :model must define a method :method()…

Error message

The model class :model must define a method :method() returning html color HEX codes for the ':field' form field.

What it means

Thrown by ColorPicker::getAvailableColors when availableColors is a string naming a model method but that method is not defined on the model class. The widget expects the method to return an array of hex color codes; the failure is the missing method itself, before any return-type check.

Solutions

  1. Define the named method on the model returning an array of HEX color strings
  2. Correct the availableColors value in the field config to an existing method name
  3. Pass the colors directly as an array in the field configuration instead
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at modules/backend/formwidgets/ColorPicker.php:134 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21). Data as JSON: /api/errors/382c07e265b7f34c. Report an issue: GitHub.

Appendix: source

Thrown at modules/backend/formwidgets/ColorPicker.php:134

        $this->vars['showInput'] = $this->showInput;
        $this->vars['readOnly'] = $this->readOnly;
        $this->vars['disabled'] = $this->disabled;
        $this->vars['isCustomColor'] = !in_array($value, $availableColors);
    }

    /**
     * getAvailableColors as a list of available colors.
     */
    protected function getAvailableColors(): array
    {
        $availableColors = $this->availableColors;
        if (is_array($availableColors)) {
            return $availableColors;
        }

        if (is_string($availableColors) && strlen($availableColors)) {
            if (!$this->model->methodExists($availableColors)) {
                throw new ApplicationException(Lang::get('backend::lang.field.colors_method_not_exists', [
                    'model' => get_class($this->model),
                    'method' => $availableColors,
                    'field' => $this->formField->fieldName
                ]));
            }

            // @deprecated just pass form field here -sg
            return (array) $this->model->{$availableColors}(
                $this->formField->fieldName,
                $this->formField->value,
                $this->formField->config
            );
        }

        return [];
    }

    /**

View on GitHub (pinned to b608633a7e)