Skip to content

Commit

Permalink
allow customisation of shortcodable DataObject list in dropdown. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sheadawson committed Sep 8, 2014
1 parent 03144dd commit 5fbf1f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,17 @@ public static function parse_shortcode($arguments, $content, $parser, $shortcode
return $gallery->customise($data)->renderWith('ImageGallery');
}
}
```
```

Create the ImageGallery.ss template then that's it, done!


### Optional configuration

If you would like to customise or filter the list of available shortcodable DataObject records available in the dropdown, you can supply a custom get_shortcodable_records static method on your shortcodable DataObject. The method should return an associative array suitable for the DropdownField. For example:

```php
public static function get_shortcodable_records(){
return ImageGallery::get()->filter('SomeField', 'SomeValue')->map()->toArray();
}
```
6 changes: 5 additions & 1 deletion code/controllers/ShortcodableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ public function ShortcodeForm(){
if (class_exists($classname)) {
$class = singleton($classname);
if (is_subclass_of($class, 'DataObject')) {
$dataObjectSource = $classname::get()->map()->toArray();
if(singleton($classname)->hasMethod('get_shortcodable_records')){
$dataObjectSource = $classname::get_shortcodable_records();
}else{
$dataObjectSource = $classname::get()->map()->toArray();
}
$fields->push(
DropdownField::create('id', $class->singular_name(), $dataObjectSource)
->setHasEmptyDefault(true)
Expand Down

0 comments on commit 5fbf1f8

Please sign in to comment.