Skip to content

Custom system dictionaries ​

Pro

System dictionaries are read-only lists that choice fields can link to, like VX's countries and currencies. Add your own from a plugin, for data that shouldn't be edited in the dashboard: product categories from an ERP, or a list of airports.

php
use VxFramework\Modules\Dictionary\Providers\Array_Provider;
use VxFramework\Modules\Dictionary\Registry;

final class My_Airports_Provider extends Array_Provider {
    public function key(): string   { return 'airports'; }
    public function label(): string { return 'Airports'; }

    protected function load_entries(): array {
        return [
            [ 'value' => 'LIS', 'label' => 'Lisbon (LIS)' ],
            [ 'value' => 'OPO', 'label' => 'Porto (OPO)' ],
        ];
    }
}

add_action( 'vxframework/dictionary/register', function () {
    Registry::register( new My_Airports_Provider() );
} );

The dictionary then appears in choice fields' system dictionary options. Keep values stable: they're what gets stored on posts.

Technical details for LLMs
  • Provider interface (VxFramework\Modules\Dictionary\Provider): key(), label(), entries(): array (each { value, label, …extra attributes }), get( string $value ): ?array. Array_Provider implements memoization and lookup; implement load_entries().
  • vxframework/dictionary/register fires once when the registry boots (lazily, after built-ins). Keys must not collide with user dictionaries or built-ins.
  • Link fields with choices_source: "system_dictionary", system_dictionary: "<key>". Only available when the Pro dictionary module is loaded.

Documentation for the VX Framework.