Created
March 8, 2018 08:12
-
-
Save bummzack/f6ae3129f0758b02ceb7336de94efeff to your computer and use it in GitHub Desktop.
Filtered files in fluent (SS3)
This file contains hidden or 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
<?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