This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add an extension to SilverStripe\Admin\LeftAndMain | |
class LeftAndMainExtension extends Extension | |
{ | |
public function someFancyAction($data, $form) | |
{ | |
// do some fancy stuff | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create an extension attached to: SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest | |
class GridFieldDetailFormItemRequestExtension extends Extension | |
{ | |
public function updateFormActions(FieldList $actions) | |
{ | |
$record = $this->owner->getRecord(); | |
// This extension would run on every GridFieldDetailForm, so ensure you ignore contexts where | |
// you are managing a DataObject you don't care about |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (isset($data['FileID']) && $data['FileID'] && $data['FileID']['error'] == 0) { | |
$attachment = $data['FileID']; | |
try { | |
$upload = Upload::create(); | |
$file = File::create(); | |
$file->Title = $attachment['name']; | |
$folder = Folder::find_or_make('Uploads/FolderName/' . Security::getCurrentUser()->ID); | |
$upload->loadIntoFile($attachment, $file, $folder->getFilename()); | |
$fileID = $file->write(); | |
$app->AttachmentID = $fileID; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static $searchable_fields = [ | |
'Title' => [ | |
'title' => 'Title' | |
], | |
'Year' => [ | |
'title' => 'Year', | |
'field' => DropdownField::class | |
], | |
'ProductType.Title' => [ | |
'title' => 'Product Type', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sometimes when implementing search functionality on a SilverStripe website, you may find youself just needing a very basic site search without wanting to implement a full-scale search platform like Solr. In that case, SilverStripe 4 by default offers the ability to search Pages and File objects directly out of the box. This functionality is handled in ContentControllerSearchExtension.php which means that any Controllers that extend off ContentController.php can enable the Site Search functionality. | |
To setup a basic site search, there are only 3 key steps required: | |
Step 1: | |
We first want to enable the search engine and this can be done simply by adding the following to mysite/_config.php. By default this will search both Pages and Files objects. If you want to restrict the search to only 1 type, you can also pass Page::class or File::class into the enable() method as a parameter: | |
FulltextSearchable::enable(); | |