Skip to content

Instantly share code, notes, and snippets.

@bummzack
Created March 8, 2018 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bummzack/f6ae3129f0758b02ceb7336de94efeff to your computer and use it in GitHub Desktop.
Save bummzack/f6ae3129f0758b02ceb7336de94efeff to your computer and use it in GitHub Desktop.
Filtered files in fluent (SS3)
<?php
/**
* Allow filtering files per locale
*/
class FluentFileFilteredExtension extends FluentFilteredExtension
{
public function canViewInLocale($locale = null)
{
if ($this->isFolder()) {
return true;
}
return parent::canViewInLocale($locale);
}
public function updateCMSFields(FieldList $fields)
{
// Don't add the filter checkboxes to folders
if ($this->isFolder()) {
return;
}
parent::updateCMSFields($fields);
}
public function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null)
{
// Disable filtering on folders
if ($this->isFolder()) {
return;
}
// Generally disable filtering of files in the backend!
if (!Fluent::is_frontend()) {
return;
}
parent::augmentSQL($query, $dataQuery);
}
private function isFolder()
{
return $this->ownerBaseClass == 'Folder' || $this->owner instanceof Folder;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment