1 | <?php |
||
2 | |||
3 | namespace DNADesign\Elemental\Extensions; |
||
4 | |||
5 | use DNADesign\Elemental\Models\ElementalArea; |
||
6 | use DNADesign\Elemental\Extensions\ElementalAreasExtension; |
||
7 | use SilverStripe\Core\Extension; |
||
8 | |||
9 | class ElementalContentControllerExtension extends Extension |
||
10 | { |
||
11 | /** |
||
12 | * @var array |
||
13 | */ |
||
14 | private static $allowed_actions = array( |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
15 | 'handleElement' |
||
16 | ); |
||
17 | |||
18 | public function handleElement() |
||
19 | { |
||
20 | $id = $this->owner->getRequest()->param('ID'); |
||
21 | |||
22 | if (!$id) { |
||
23 | user_error('No element ID supplied', E_USER_ERROR); |
||
24 | return false; |
||
25 | } |
||
26 | |||
27 | /** @var SiteTree $elementOwner */ |
||
28 | $elementOwner = $this->owner->data(); |
||
29 | |||
30 | $elementalAreaRelations = $this->owner->getElementalRelations(); |
||
31 | |||
32 | if (!$elementalAreaRelations) { |
||
33 | user_error(get_class($this->owner) . ' has no ElementalArea relationships', E_USER_ERROR); |
||
34 | return false; |
||
35 | } |
||
36 | |||
37 | foreach ($elementalAreaRelations as $elementalAreaRelation) { |
||
38 | $element = $elementOwner->$elementalAreaRelation()->Elements() |
||
39 | ->filter('ID', $id) |
||
40 | ->First(); |
||
41 | |||
42 | if ($element) { |
||
43 | return $element->getController(); |
||
44 | } |
||
45 | } |
||
46 | |||
47 | user_error('Element $id not found for this page', E_USER_ERROR); |
||
48 | return false; |
||
49 | } |
||
50 | } |
||
51 |