1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverCommerce\CatalogueFrontend\Control; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Core\ClassInfo; |
6
|
|
|
use SilverStripe\Core\Injector\Injector; |
7
|
|
|
use SilverStripe\ORM\DataObject; |
8
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
9
|
|
|
use SilverStripe\CMS\Controllers\ModelAsController as CMSModelAsController; |
10
|
|
|
use SilverCommerce\CatalogueAdmin\Model\CatalogueCategory; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Customise default @link ModelAsController to allow for finding and setting |
14
|
|
|
* of catalogue categories or products. |
15
|
|
|
*/ |
16
|
|
|
class ModelAsController extends CMSModelAsController |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Get the appropriate {@link CatalogueProductController} or |
20
|
|
|
* {@link CatalogueProductController} for handling the relevent |
21
|
|
|
* object. |
22
|
|
|
* |
23
|
|
|
* @param $object A {@link DataObject} with the getControllerName() method |
|
|
|
|
24
|
|
|
* @param string $action |
25
|
|
|
* @return CatalogueController |
26
|
|
|
*/ |
27
|
|
|
public static function controller_for_object($object, $action = null) |
28
|
|
|
{ |
29
|
|
|
$controller = $object->getControllerName(); |
30
|
|
|
|
31
|
|
|
if ($action && class_exists($controller . '_' . ucfirst($action))) { |
32
|
|
|
$controller = $controller . '_' . ucfirst($action); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return Injector::inst()->create($controller, $object); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return ContentController |
|
|
|
|
40
|
|
|
* @throws Exception If URLSegment not passed in as a request parameter. |
41
|
|
|
*/ |
42
|
|
|
public function getNestedController() |
43
|
|
|
{ |
44
|
|
|
$request = $this->getRequest(); |
45
|
|
|
|
46
|
|
|
if (!$URLSegment = $request->param('URLSegment')) { |
47
|
|
|
throw new Exception('ModelAsController->getNestedController(): was not passed a URLSegment value.'); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
// Find page by link, regardless of current locale settings |
51
|
|
|
if (class_exists('Translatable')) { |
52
|
|
|
Translatable::disable_locale_filter(); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// Select child page |
56
|
|
|
$sitetree_conditions = ["URLSegment" => rawurlencode($URLSegment)]; |
57
|
|
|
$cat_conditions = $sitetree_conditions; |
58
|
|
|
$product_conditions = $sitetree_conditions; |
|
|
|
|
59
|
|
|
|
60
|
|
|
if (SiteTree::config()->get('nested_urls')) { |
61
|
|
|
$sitetree_conditions['ParentID'] = 0; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$cat_conditions['ParentID'] = 0; |
65
|
|
|
|
66
|
|
|
$object = SiteTree::get() |
67
|
|
|
->filter($sitetree_conditions) |
68
|
|
|
->first(); |
69
|
|
|
|
70
|
|
|
if (!$object) { |
71
|
|
|
$object = CatalogueCategory::get() |
72
|
|
|
->filter($cat_conditions) |
73
|
|
|
->first(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
// Check translation module |
77
|
|
|
// @todo Refactor out module specific code |
78
|
|
|
if (class_exists('Translatable')) { |
79
|
|
|
Translatable::enable_locale_filter(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
if (!$object) { |
83
|
|
|
$this->httpError(404, 'The requested page could not be found.'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
// Enforce current locale setting to the loaded SiteTree object |
87
|
|
|
if (class_exists('Translatable') && $object->Locale) { |
88
|
|
|
Translatable::set_current_locale($object->Locale); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
if (isset($_REQUEST['debug'])) { |
92
|
|
|
Debug::message("Using record #$object->ID of type " . get_class($object) . " with link {$sitetree->Link()}"); |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return self::controller_for_object($object, $this->getRequest()->param('Action')); |
96
|
|
|
} |
97
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths