XF 2.2 JSON_ARRAY column and allowedValues


Well-known member
Hello all!
Let's say we have a JSON_ARRAY column (entity) and we need to specify allowedValues.

How could be achieved?
        $structure->columns = [
            'user_id'   => ['type' => self::UINT, 'required' => true],
            'days' => ['type' => self::JSON_ARRAY, 'default' => [],
                'allowedValues' => ['', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']]
The above example of allowedValues will work with STR type, but not for JSON_ARRAY.
Any idea?

Jeremy P

XenForo developer
Staff member
You could use a verifier method. Something like (untested)...

protected function verifyDays(array $values, string $key, int $type, array $columnOptions): bool 
    if (!empty(array_diff($values, $columnOptions['allowedValues'])
        $this->error(\XF::phrase('some_phrase'), $key);
        return false;

    return true;

It will be automatically called if it exists (based on the column name), or you can set a custom method name using the verify column option.