Completed
Push — master ( 6dd01c...5851ba )
by
unknown
20s queued 10s
created

CKANRegistryPageController::getBasePath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\CKANRegistry\Page;
4
5
use PageController;
0 ignored issues
show
Bug introduced by
The type PageController was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use SilverStripe\CKANRegistry\Model\Resource;
7
use SilverStripe\ORM\DataObject;
8
9
class CKANRegistryPageController extends PageController
10
{
11
    private static $url_handlers = [
0 ignored issues
show
introduced by
The private property $url_handlers is not used, and could be removed.
Loading history...
12
        // Route all requests for this page, including sub-URLs, to the index action.
13
        // The frontend components should take care of handling sub-URL routing from here.
14
        'view/$Item' => 'index',
15
    ];
16
17
    /**
18
     * Loads model data encapsulated as JSON in order to power front end technologies used to render that
19
     * data. Includes critical info such as the CKAN site to query (e.g. which domain, datastore, etc.)
20
     * but also can be extended to be used for configuring the component used to show this (e.g. React.js
21
     * or Vue.js component configuration).
22
     *
23
     * @param DataObject $holder
24
     * @return array
25
     */
26
    public function getCKANClientConfig(DataObject $holder = null)
27
    {
28
        if (!$holder) {
29
            $holder = $this->data();
30
        }
31
32
        /** @var Resource $resource */
33
        $resource = $holder->getComponent('DataResource');
34
35
        $config = [
36
            'spec' => [
37
                'endpoint' => $resource->Endpoint,
38
                'dataset' => $resource->DataSet,
39
                'identifier' => $resource->Identifier,
40
            ],
41
            'name' => $resource->Name,
42
            'resourceName' => $resource->ResourceName,
43
            'basePath' => $this->getBasePath($holder),
44
        ];
45
46
        $this->extend('updateCKANClientConfig', $config);
47
48
        return $config;
49
    }
50
51
    /**
52
     * Returns the base path for the resource's page with a leading slash
53
     *
54
     * @param DataObject $holder
55
     * @return string
56
     */
57
    public function getBasePath(DataObject $holder = null)
58
    {
59
        if (!$holder) {
60
            return '/';
61
        }
62
63
        $link = $holder->RelativeLink();
64
        return '/' . trim($link, '/');
65
    }
66
}
67