1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\CKANRegistry\Forms; |
4
|
|
|
|
5
|
|
|
use SilverStripe\CKANRegistry\Model\Resource; |
6
|
|
|
use SilverStripe\Core\Injector\Injectable; |
7
|
|
|
use SilverStripe\Forms\GridField\GridField_HTMLProvider; |
8
|
|
|
use SilverStripe\View\ArrayData; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Presents a title for the {@link Resource} data set and selected resource, as well as a toggle to hide or show |
12
|
|
|
* the resource locator field in the CMS. |
13
|
|
|
* |
14
|
|
|
* This component is designed to be used on CKANRegistryPage instances. |
15
|
|
|
*/ |
16
|
|
|
class GridFieldResourceTitle implements GridField_HTMLProvider |
17
|
|
|
{ |
18
|
|
|
use Injectable; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var Resource |
22
|
|
|
*/ |
23
|
|
|
protected $resource; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $targetFragment = ''; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param Resource $resource |
32
|
|
|
* @param string $targetFragment |
33
|
|
|
*/ |
34
|
|
|
public function __construct(Resource $resource, $targetFragment = 'buttons-before-left') |
35
|
|
|
{ |
36
|
|
|
$this->setResource($resource); |
37
|
|
|
$this->setTargetFragment($targetFragment); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function getHTMLFragments($gridField) |
41
|
|
|
{ |
42
|
|
|
$data = ArrayData::create([ |
43
|
|
|
'Resource' => $this->resource, |
44
|
|
|
'EditLinkTitle' => _t(__CLASS__ . '.EDIT_LINK_TITLE', 'Edit resource'), |
45
|
|
|
]); |
46
|
|
|
$result = $data->renderWith(__CLASS__); |
47
|
|
|
|
48
|
|
|
return [ |
49
|
|
|
$this->targetFragment => $result, |
50
|
|
|
]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param Resource $resource |
55
|
|
|
* @return $this |
56
|
|
|
*/ |
57
|
|
|
public function setResource(Resource $resource) |
58
|
|
|
{ |
59
|
|
|
$this->resource = $resource; |
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $targetFragment |
65
|
|
|
* @return $this |
66
|
|
|
*/ |
67
|
|
|
public function setTargetFragment($targetFragment) |
68
|
|
|
{ |
69
|
|
|
$this->targetFragment = (string) $targetFragment; |
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|