Skip to content

Instantly share code, notes, and snippets.

@curtisblackwell
Last active January 2, 2016 01:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save curtisblackwell/5814291 to your computer and use it in GitHub Desktop.
Save curtisblackwell/5814291 to your computer and use it in GitHub Desktop.
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