Issues (26)

src/Controllers/TaxonomyDirectoryController.php (1 issue)

1
<?php
2
3
namespace SilverStripe\Taxonomy\Controllers;
4
5
use Page;
6
use PageController;
7
use SilverStripe\Control\HTTPRequest;
8
use SilverStripe\ORM\ArrayList;
9
use SilverStripe\View\ArrayData;
10
use SilverStripe\View\SSViewer;
11
12
if (!class_exists(PageController::class)) {
13
    return;
14
}
15
16
/**
17
 * Class TaxonomyDirectoryController
18
 *
19
 * Controller for returning a list of pages tagged with a specific Taxonomy Term
20
 */
21
class TaxonomyDirectoryController extends PageController
22
{
23
24
    private static $allowed_actions = array(
0 ignored issues
show
The private property $allowed_actions is not used, and could be removed.
Loading history...
25
        'index'
26
    );
27
28
    public function index(HTTPRequest $request)
29
    {
30
        $termString = $request->param('ID');
31
32
        $pages = Page::get()->filter(['Terms.Name' => $termString]);
33
34
        return $this->customise(new ArrayData(array(
35
            'Title' => $termString,
36
            'Term' => $termString,
37
            'Pages' => $pages,
38
            'Breadcrumbs' => $this->renderBreadcrumb($termString)
39
        )))->renderWith(array(__CLASS__, "Page"));
40
    }
41
42
    protected function renderBreadcrumb($termString)
43
    {
44
        $page = new Page();
45
        $page->Title = $termString;
46
47
        $template = new SSViewer('BreadcrumbsTemplate');
48
        return $template->process($this->customise(new ArrayData(array(
49
            "Pages" => new ArrayList(array($page))
50
        ))));
51
    }
52
}
53