Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Statamic Suggest Hack

Statamic Suggest Hack

This is a hack on Statamic's Suggest fieldtype to allow options to be passed in via a separate file. This way global variables can populate the options.

Usage

Paste the code from ft.suggest.hack.php into cp/fieldtypes/suggest/ft.suggest.php after the "Hardcoded list of options" section.

In your fieldset, do something like this:

brand:
  display: Brand
  type: suggest
  file:
    path: _config/global_variables.yaml
    variable: brands
/*
|--------------------------------------------------------------------------
| Hardcoded list of options by file
|--------------------------------------------------------------------------
|
| This works just like options, but reads them from a YAML file.
|
*/
if (isset($this->field_config['file'])) {
$config = $this->field_config['file'];
$path = Spyc::YAMLLoad(array_get($config, 'path', '_config/settings.yaml'));
$variable = array_get($config, 'variable');
$options = array_get($path, $variable);
$suggestions = array_merge($suggestions, $options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment