Silverstripe Version: 4*
Question:
I want to display the folder structure for the files that are found through frontend search.
So for example:
In the admin/assets/ section I created a subfolder within Uploads folder and then added another subfolder and then uploaded a file:
Uploads/Subfolder_1/Subfolder_2/MyFile.pdf
I extended the Search form for customizing the results on the frontend.
Now I need to display the folder structure for the files that are found through search
For the example that would be: Uploads / Subfolder_1 / Subfolder_2
class MySearchForm extends SearchForm
{
public function getResults()
{
$request = $this->getRequestHandler()->getRequest();
$keywords = $this->getKeywords($request);
$resultsPerPage = $this->getPageLength();
$start = max(0, (int)$request->requestVar('start'));
$booleanSearch =
strpos($keywords, '"') !== false ||
strpos($keywords, '+') !== false ||
strpos($keywords, '-') !== false ||
strpos($keywords, '*') !== false;
$results = DB::get_conn()->searchEngine($this->classesToSearch, $keywords, $start, $resultsPerPage, "\"Relevance\" DESC", "", $booleanSearch);
$results = $this->canViewPost($results);
$results = $this->isFileInResult($results);
return $this->processResult($results, $keywords);
}
private function processResult($results, $keywords)
{
$processedKeywords = str_replace(array('"', '*'), '', $keywords);
foreach ($results as $result) {
$result->Content = preg_replace('/(' . preg_quote($processedKeywords, "/") . ')/i', "<span class=\"highlight-search-result\">\$0</span>", $result->Content);
$result->Title = preg_replace('/(' . preg_quote($processedKeywords, "/") . ')/i', "<span class=\"highlight-search-result\">\$0</span>", $result->Title);
// Is there a simple way to get the folder structure?
if ($result->ClassName === "SilverStripe\Assets\File") {
$result->FileFolders = ???
}
}
return $results;
}
Is there a simple method to get the folder structure? Or the full path?